英文:
How to get date and time in below format in java?
问题
Sure, here's the translation:
如何获取当前日期和时间,并将其转换为以下字符串格式?
06-04-2020 05:00 PM
之后我需要在日期上加上几分钟?请帮忙!
英文:
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
After that I need to add few minutes to the date? Please help!
答案1
得分: 4
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"))));
英文:
Your answer should look something like this:
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.
答案2
得分: 2
Date yourDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy h:m a");
String formatedDate = sdf.format(yourDate);
英文:
Date yourDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy h:m a");
String formatedDate= sdf.format(yourDate);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论