如何在 java 中获取以下格式的日期和时间?
How to get date and time in below format in java?
如何获取当前日期和时间以及如何将其转换为以下字符串格式?
06-04-2020 05:00下午
在那之后我需要在日期上加几分钟?请帮忙!
您的答案应如下所示:
String dateTimePattern = "dd-MM-yyyy HH:mm a";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimePattern );
LocalDateTime yourDay= LocalDateTime.of(2020, 4, 6, 17, 00);
System.out.println(formatter.format(ZonedDateTime.of(yourDay, ZoneId.of("UTC-5"))));
请查看 this 以获取有关可用格式的更多信息。
Date yourDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy h:m a");
String formatedDate= sdf.format(yourDate);
如何获取当前日期和时间以及如何将其转换为以下字符串格式?
06-04-2020 05:00下午
在那之后我需要在日期上加几分钟?请帮忙!
您的答案应如下所示:
String dateTimePattern = "dd-MM-yyyy HH:mm a";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateTimePattern );
LocalDateTime yourDay= LocalDateTime.of(2020, 4, 6, 17, 00);
System.out.println(formatter.format(ZonedDateTime.of(yourDay, ZoneId.of("UTC-5"))));
请查看 this 以获取有关可用格式的更多信息。
Date yourDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy h:m a");
String formatedDate= sdf.format(yourDate);