gpt4 book ai didi

java - 给定日期的正确日期格式是什么

转载 作者:行者123 更新时间:2023-12-01 15:42:39 25 4
gpt4 key购买 nike

此日期实例的正确日期格式是什么..

10/10/2011 2:36:00 PM

我用过这个..

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss a");

编辑

更多代码

Object temp = jsonArray.getJSONObject(i).get("STARTDATE"); // date object from webserive
Date appointment.mStartDate = formatter.parse(temp.toString());

但它以这种格式返回了这个日期..

Thu Nov 10 00:36:00 GMT+02:00 2011

最佳答案

but it returned this date in this format ..

Thu Nov 10 00:36:00 GMT+02:00 2011

您是在这样做System.out.println(appointment.mStartDate);吗?那么就完全没问题了。这确实是the Date#toString() method的默认格式。 。当您将非 String 对象传递给 System.out.println() 时,其 toString() 方法 will be called并且将显示返回的String

如果您想以与检索时相同的格式显示它,那么您应该使用 SimpleDateFormat#format() 方法将 Date 转换为所需格式的字符串:

String dateString = formatter.format(appointment.mStartDate);
System.out.println(dateString);

关于java - 给定日期的正确日期格式是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7777717/

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