Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created February 21, 2024 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbmeeks/3cf66776b5e1bd3e337a87400040fcf5 to your computer and use it in GitHub Desktop.
Save cbmeeks/3cf66776b5e1bd3e337a87400040fcf5 to your computer and use it in GitHub Desktop.
Convert Odd DateTime String
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
public class Main {
public static void main(String[] args) throws ParseException {
final String dateTime = "20240310 120600.000";
final String format = "yyyyMMdd HHmmss.000";
// format incoming date/time string using custom format
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date date = sdf.parse(dateTime);
// convert standard Java.Util.Date object to LocalDateTime using system TimeZone
LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
// output passed in date minus 14 hours (shows previous day)
System.out.println(localDateTime.minusHours(14));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment