简体   繁体   中英

Android.text.format.Time not setting isDst correctly?

I'm trying to set a Time object to be 15 minutes past the current time, according to following:

    Time time = new Time("EST");
    time.setToNow();
    time.minute += 15;
    time.normalize(true);

However, after time.setToNow(), I notice in the debugger that the time object's isDST field equals 0, which indicates not in DST according to the reference. Also according to the reference, time.normalize(true) method is supposed to set the isDst field to -1, then compute the correct value for isDst, but in my case the isDst value stays the same, at 0, so the time is shifted back one hour.

I know we're in DST now, so I expect the isDst field to reflect this, but it's not. Any ideas?

I know we're in DST now, so I expect the isDst field to reflect this, but it's not. Any ideas?

It's possible that it's because you've given "EST" as a time zone. That's Eastern standard time - which has no concept of DST.

If you use something like "America/New_York" instead, I suspect you'll get a different answer. That's a zoneinfo time zone identifier, which covers both EST and EDT at different points in the year.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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