note : LocalDateTime is
1. LocalDateTime converted to custom time format string
public static String getDateTimeAsString(LocalDateTime localDateTime, String format) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
return localDateTime.format(formatter);
}
2. Convert long type timestamp to LocalDateTime
public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp);
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
3. LocalDateTime to long type timestamp
public static long getTimestampOfDateTime(LocalDateTime localDateTime) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return instant.toEpochMilli();
}
4. LocalDateTime
converts a time string to a custom time format
public static LocalDateTime parseStringToDateTime(String time, String format) {
DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
return LocalDateTime.parse(time, df);
}
p>
p>
div>
Read More:
- 1、 Java 8 date and local date
- ‘Conversion failed when converting date and/or time from character string.DB-Lib error message 241,
- Mutual conversion between date and localdatetime
- How to get the current time in java time string
- Linux view current date and time
- Vitis: platform out of date, makefile error at compile time; The modified application compiles to undefined reference
- java.text.ParseException: Unparseable date: “2021-06-24“
- [Solved] Flowable Start Error: ClassCastException: java.time.LocalDateTime cannot be cast to java.lang.String
- Java lossy conversion
- Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- The time of the time database displayed by the front end is inconsistent
- When calling time module – time / datetime in wxPython, an error is reported. Valueerror: unknown locale: zh cn
- Get the current date in Python
- Error attempting to get column time from result set. Cause: java.sql.SQLFe
- Time, strftime and strptime in Python
- Register global time filter in main.js in Vue
- Set the default time to the current value in MySQL
- After switching the tidb database, an error could not commit JDBC transaction appears from time to time
- Link: fatal error lnk1123: failure during conversion to coff: file in
- ERROR 2026 (HY000): SSL connection error: ASN: before date in the future