1publicstaticvoidmain(String[] args) {2DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");3LocalDateTime time =LocalDateTime.now();4String localTime =df.format(time);5LocalDateTime ldt = LocalDateTime.parse("2018-01-12 17:07:05",df);6System.out.println("LocalDateTime转...
import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Test { public static void main(String[] args) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String timeStr = formatter.format(now);...
String转LocalDate和LocalDateTime 代码 @Testpublic voidString转LocalDate和LocalDateTime(){Stringstr="2017-11-21 14:41:06:612";DateTimeFormatterfmt=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS");LocalDatedate=LocalDate.parse(str,fmt);LocalDateTimetime=LocalDateTime.parse(str,fmt);System.out.p...
privateSimpleDateFormatsdf =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式Datenow =newDate();Stringtime = sdf.format(now); 方法二(线程安全,建议使用) importjava.time.LocalDateTime;importjava.time.format.DateTimeFormatter;publicclasstestMain{publicstaticvoidmain(String[] args) {// yyy...
Java爬坑--LocalDateTime与String⽇期互相转换1public static void main(String[] args) { 2 DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");3 LocalDateTime time = LocalDateTime.now();4 String localTime = df.format(time);5 LocalDateTime ldt = LocalDateTime.pars...
setLocalDateTime(LocalDateTime.now()); String json = JSON.toJSONString(localDateTimeVO); ...
String dateTimeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));System.out.println("当前字符串日期时间:" + dateTimeStr);4. String转LocalDateTime 我们也可以使用parse()方法从字符串中解析日期时间对象。LocalDateTime dateTime = LocalDateTime.parse(dateTimeStr, ...
//时间转字符串格式化DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");String dateTime=LocalDateTime.now(ZoneOffset.of("+8")).format(formatter);//字符串转时间String dateTimeStr="2018-07-28 14:11:15";DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");Loc...
有没有办法将日期String转换为LocalDateTime其中格式"yyyy-MM-dd"? 如果我试试这个: DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDateTime ldt = LocalDateTime.parse(string, DATEFORMATTER); 我得到这个例外: java.time.format.DateTimeParseException: Text '2017-03-13' could...
LocalDateTime convertTimeZoneStringToLocalDateTime(String timeZoneDateTimeStr){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); OffsetDateTime offsetDateTime = OffsetDateTime.parse(timeZoneDateTimeStr, formatter);return offsetDateTime.toLocalDateTime(); }}这里...