|
Hello,
I have the number of seconds since 1/1/1970 - 1275491109 I want to convert that to more readable date. Here is what I have come up with so far. dateInt = 1275491109 t = dateInt.toLong() // convert to Long t = t.multiply(1000); //convert seconds to milliseconds def tz= TimeZone.'default' t = t.minus(tz.rawOffset) // deal with the timeZone offset new Date(t).toString() //get a string back -->Wed Jun 02 16:05:09 PDT 2010 So this seems to work, but I am pretty noobish, so I am wondering if I am missing anything. Is there a better way to do this? Thanks Todd |
|
Just...
dateInt = 1275491109 new Date(dateInt * 1000) read the docs for Java Date... Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT. You don't need to muck with TimeZone. On Mon, Nov 29, 2010 at 1:51 AM, toddgeist <[hidden email]> wrote:
|
|
Thanks for responding :>)
but I either I am still missing something or you need to muck about with the TimeZone. if run this in the groovyConsole groovy> dateInt = 0 groovy> new Date(dateInt * 1000) Result: Wed Dec 31 16:00:00 PST 1969 That is off by exactly the offset in my default timeZone. I am in PST. I am running groovy 1.7.5 |
|
or heck even simpler...
groovy> new Date(0); Result: Wed Dec 31 16:00:00 PST 1969 |
|
What about:
dateInt = 1275491109 use( groovy.time.TimeCategory ) { new Date() + dateInt.seconds } On 28 November 2010 16:14, toddgeist <[hidden email]> wrote:
|
|
Sorry:
dateInt = 1275491109 theDate = use( groovy.time.TimeCategory ) { new Date() + dateInt.seconds } println theDate Tim On 29 November 2010 08:03, Tim Yates <[hidden email]> wrote: What about: |
|
For the record, I am an idiot:
dateInt = 1275491109 theDate = use( groovy.time.TimeCategory ) { new Date( 0 ) + dateInt.seconds } println theDate Needed to call new Date() with 0 as the parameter (I think) Tim On 29 November 2010 08:04, Tim Yates <[hidden email]> wrote: Sorry: |
| Powered by Nabble | Edit this page |
