Author Topic: [Java] Converting Windows FileTimes to java.lang.Dates  (Read 8254 times)

0 Members and 1 Guest are viewing this topic.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
[Java] Converting Windows FileTimes to java.lang.Dates
« on: November 01, 2007, 03:37:46 pm »
If you live in a DST observing timezone, these numbers will be one hour off this week. This appears to be a bug with Java not respecting the new DST rules.

Funny how we'll throw an entire week in to chaos to avoid two hours of confusion during a time when normal people are asleep.

Code: [Select]
/**
* Converts a Windows FileTime structure to a Date
* @param ft contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
* @return a Date with the correct time
*/
public static Date fileTime(long ft) {
// Date.parse("1/1/1601") == 11644455600000L
long date = ft / 10000 - 11644455600000L;
date += TimeZone.getDefault().getOffset(date);
return new Date(date);
}

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: [Java] Converting Windows FileTimes to java.lang.Dates
« Reply #1 on: November 01, 2007, 05:03:30 pm »
DST is retarded anyway :/  The primary cause for it's use to begin with isn't even necessary anymore.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: [Java] Converting Windows FileTimes to java.lang.Dates
« Reply #2 on: November 01, 2007, 06:36:58 pm »
DST is retarded anyway :/  The primary cause for it's use to begin with isn't even necessary anymore.
You mean to encourage people to shop for an extra hour during the summer? 

Or is that just the conspiracy theory? :)

Offline Skywing

  • Full Member
  • ***
  • Posts: 139
    • View Profile
    • Nynaeve
Re: [Java] Converting Windows FileTimes to java.lang.Dates
« Reply #3 on: November 01, 2007, 08:30:32 pm »
DST is retarded anyway :/  The primary cause for it's use to begin with isn't even necessary anymore.

I'm not all that enthusiastic about DST either, but the reasons for it are certainly still relevant today with continually rising energy prices.

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: [Java] Converting Windows FileTimes to java.lang.Dates
« Reply #4 on: November 01, 2007, 10:26:37 pm »
I'm not all that enthusiastic about DST either, but the reasons for it are certainly still relevant today with continually rising energy prices.
Energy savings were shown in multiple cases to be negligible or just plain not there.

http://www.env-econ.net/2007/03/are_daylight_sa.html
http://www.ucei.berkeley.edu/PDF/csemwp163.pdf

Quote
You mean to encourage people to shop for an extra hour during the summer?
No, to give farmers an extra hour of daylight to match up with the economy's trading hours.