gpt4 book ai didi

java - 从此格式获取当前日期 2019-06-30

转载 作者:行者123 更新时间:2023-12-02 09:49:04 25 4
gpt4 key购买 nike

我该怎么做?

Year 2019, Month July, Date 30

仅采用此格式并来自日历 (java.util) 对象

<小时/>
private String getCurrentDate() {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat mdformat = new SimpleDateFormat("yyyy-MM-dd");
return mdformat.format(calendar.getTime()); }

最佳答案

如果您只想使用日历:

Calendar c = Calendar.getInstance();
String result = "Year " + c.get(Calendar.YEAR) +
", Month " + new SimpleDateFormat("MMMM").format(c.getTime()) +
", Date " + c.get(DAY_OF_MONTH);
System.out.println(result);

将打印:

Year 2019, Month June, Date 4

如果您甚至不想使用SimpleDateFormat:

String[] months = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
Calendar c = Calendar.getInstance();
String result = "Year " + c.get(Calendar.YEAR) +
", Month " + months[c.get(Calendar.MONTH)] +
", Date " + c.get(DAY_OF_MONTH);
System.out.println(result);

还将打印:

Year 2019, Month June, Date 4

关于java - 从此格式获取当前日期 2019-06-30,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56447232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com