Created
February 21, 2024 20:45
-
-
Save cbmeeks/3cf66776b5e1bd3e337a87400040fcf5 to your computer and use it in GitHub Desktop.
Convert Odd DateTime String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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