Skip to content

Instantly share code, notes, and snippets.

@rmg007
Created October 21, 2022 11:56
Show Gist options
  • Save rmg007/239ea0f7ed8844407de50b5b6c21bd4b to your computer and use it in GitHub Desktop.
Save rmg007/239ea0f7ed8844407de50b5b6c21bd4b to your computer and use it in GitHub Desktop.
Local Date Time Example
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Locale;
import java.time.LocalDateTime;
public class LocalDateTimeExample {
public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
System.out.println(now);
//String isoFormat = now.format(DateTimeFormatter.ISO_TIME);
//System.out.println(isoFormat);
//
//String patternFormat = now.format(DateTimeFormatter.ofPattern("E, MMM dd hh:mm a"));
//System.out.println(patternFormat);
//String italianLocale = now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.ITALIAN));
//System.out.println( italianLocale);
String chineseLocale = now.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.CHINA));
System.out.println(chineseLocale);
LocalDateTime lastVisit = LocalDateTime.of(2021, Month.JANUARY, 25, 6, 30);
LocalDateTime lastUpdate = LocalDateTime.parse("2023-12-30T13:45:50.63", DateTimeFormatter.ISO_LOCAL_DATE_TIME);
//System.out.println(lastUpdate);
LocalDate date = LocalDate.now();
LocalTime time = LocalTime.now();
LocalDateTime dateTime = date.atTime(time);
System.out.println(dateTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment