System.out.println(DateTimeFormatter.ofPattern("dd/MM/yyyy - hh:mm").format(date2)); 而且我和洛杉矶不在同一个时区。 编辑2: 找到了如何更改时区: // Change this: ZonedDateTime date2 = date.of(date.toLocalDateTime(), la); // incorrec
ENimport java.text.NumberFormat; import java.util.Locale; import java.util.Scanner; public class F...
Java example to use custom formatter to format a zoned datetime instance to string. DateTimeFormatterformatter=DateTimeFormatter.ofPattern("MM/dd/yyyy - HH:mm:ss z");ZonedDateTimezdt=ZonedDateTime.now();StringformattedZdt=zdt.format(formatter);System.out.println(formattedZdt); Program output. 02/...
int compareTo(ChronoZonedDateTime<?> other)比较两个日期时间zdt1.compareTo(zdt2) 格式化与字符串转换 方法描述示例 String format(DateTimeFormatter formatter)格式化为字符串zdt.format(DateTimeFormatter.ISO_ZONED_DATE_TIME) String toString()转换为ISO格式字符串"2023-06-15T14:30:45+08:00[Asia/Shanghai]...
String format=zonedDateTime.format(dateFormat); System.out.println(format);//转换时间对象Date date = MyDateUtil.dateStrToDate("yyyy-MM-dd HH:mm:ss", format); System.out.println(MyDateUtil.dateToDateStr(date)); }
ZonedDateTime 修改时区,并进行格式化 implementation("cn.hutool:hutool-all") 1. funZonedDateTime.toLocalDateStr():String= DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_TIME_PATTERN).format(this.withZoneSameInstant(ZoneId.of("UTC+8"))) 1. 2....
fun ZonedDateTime.toLocalDateStr(): String = DateTimeFormatter.ofPattern(DatePattern.CHINESE_DATE_PATTERN).format(this.withZoneSameInstant(ZoneId.of("UTC+8"))) 1. 2. val createdAt: ZonedDateTime = ZonedDateTime.now() val createdAtStr = createdAt.toLocalDateStr() ...
// ZonedDateTime zdt=ZonedDateTime.ofInstant(now.toInstant(), systemDefault); // System.out.println(zdt); // System.out.println(str); //String 转为LocalDateTime 然后转为ZonedDateTime // DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ...
public ZonedDateTime parseToZonedDateTime(String date, String dateFormat) { // use java.time from java 8 DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat); ZonedDateTime zonedDateTime = null; try { zonedDateTime = ZonedDateTime.parse(date, formatter); } catch (DateTimeException...
DateTimeFormatter isoDateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").withZone(ZoneOffset.UTC);String isoDateTimeString=isoDateTimeFormatter.format(date.toInstant());xmlGregorianCalendar=DatatypeFactory.newInstance().newXMLGregorianCalendar(isoDateTimeString); ...