如何在Java中以以下格式获取日期和时间? [英] How to get date and time in below format in java?
本文介绍了如何在Java中以以下格式获取日期和时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取当前日期和时间,以及如何将其转换为以下字符串格式?
How can I get the current date and time and how can I transfer it into the following String format?
06-04-2020 05:00 PM
06-04-2020 05:00 PM
之后,我需要在日期前加上几分钟?
After that I need to add few minutes to the date? Please help!
推荐答案
您的答案应如下所示:
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"))));
请查看此,以获取有关可用格式的更多信息。
Please look this up for more info on the available formats.
这篇关于如何在Java中以以下格式获取日期和时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文