如何获取当前日期和时间,以及如何将其转换为以下字符串格式?
06-04-2020 05:00 PM
之后,我需要在日期上加上几分钟吗?请帮助!
您的答案应如下所示:
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);