简体   繁体   English

Calendar.getInstance()返回与当前日期不同的DayOfWeek和Date

[英]Calendar.getInstance() return DayOfWeek and Dates different from the current

I have gotten Calendar class to work in my application, but the calendar does not correctly return current date and time. 我已经在我的应用程序中使用Calendar类,但是日历不能正确返回当前日期和时间。 For instance, the date returned from this class changes earlier than the actual time ( I am in East Coast of US, so I use EST ) 例如,此类的返回日期更改为早于实际时间(我在美国东海岸,所以我使用EST)

I want the Calendar to return EST, and the Calendar.getInstance seems to return time/date of a different time zone. 我希望Calendar返回EST,而Calendar.getInstance似乎返回不同时区的时间/日期。

Does anyone know how to set the calendar to the date and time of the US East Coast (EST)? 有人知道如何将日历设置为美国东海岸(EST)的日期和时间吗?

(also for day of the Week, 1 is Sunday, 2 is Monday and so on right? This does not match with the current day of the week. I suppose I could arrage the number and assume 1 is Wednesday, 2 is thursday in order to make the Week day appear in my textView correctly, but what are 1 ~ 7 numbers mean, in default?) (同样对于星期几,1是星期天,2是星期一,依此类推?这与星期几是不匹配的。我想我可以设置数字,并假设1是星期三,2是星期四)使工作日正确显示在我的textView中,但是默认情况下1〜7是什么意思?)

您可以在创建日历实例时设置时区。

Calendar c = Calendar.getInstance(TimeZone.getTimeZone("EST"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM