Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
date= Calendar.getInstance(); Date currentDate = date.getTime(); String sDate = currentDate.toString();
这将返回时间 EST。我需要将其更改为亚利桑那时间,这很棘手,因为亚利桑那没有夏令时。进行更改是否有捷径,或者我是否需要查询日历以在亚利桑那州处于 MST 时减去两个小时,而在 PST 时减去三个小时。
这将返回时间 EST。
好吧,Date.toString()如果你现在在EST 的话。它不是存储在其中的数据的一部分Date——这只是一个瞬间,不知道它可能是从哪个时区或日历系统开始的。
Date.toString()
Date
您的前两行将更简单地写为:
Date currentDate = new Date();
您应该使用 aDateFormat将 转换Date为String. 您可以在此处指定要使用的时区。不要在自己添加/删除偏移量的日期上开始执行任何算术 - 这表明您正朝着错误的方向前进。
DateFormat
String