de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Convert Unix time to normal time
PostPosted: Thu Nov 03, 2011 9:00 pm 
Offline
Active member
Hi

Is there a way to convert the unix time used to a normal date and/or time?

Also, is there a way to enter data in a seperate file, a bit of a log?

Wiliam


Top
 Profile Send private message 
 
 Re: Convert Unix time to normal time
PostPosted: Thu Nov 03, 2011 9:51 pm 
Offline
Site Admin
User avatar
Quote:
Is there a way to convert the unix time used to a normal date and/or time?

It is quite simple
To show a date/time
Code:
def text = new Date().format( "yyyy-MM-dd HH:mm:ss")
show(text)

To get separated values
Code:
def text = Calendar.getInstance().get(Calendar.YEAR)+"-"+
  Calendar.getInstance().get(Calendar.MONTH)+"-"+
  Calendar.getInstance().get(Calendar.DAY_OF_MONTH)+" "+
  Calendar.getInstance().get(Calendar.HOUR_OF_DAY)+":"+
  Calendar.getInstance().get(Calendar.MINUTE)+":"+
  Calendar.getInstance().get(Calendar.SECOND));
show(text)


Conversion is harder (and the result may suffer from the time zones) :
Code:
def t = getTime()
def text = new Date(t*1000L).format( "yyyy-MM-dd HH:mm:ss"))
show(text)


All those codes will show something like : 2014-11-3 12:14:47


Quote:
Also, is there a way to enter data in a seperate file, a bit of a log?

Yes
Code:
def f= new File('log.txt')
f.append("ok\n")


Sources :
http://groovy.codehaus.org/Getting+Started+Guide
Isn't Groovy lovely ?


Top
 Profile Send private message 
 
 Re: Convert Unix time to normal time
PostPosted: Thu Nov 03, 2011 11:39 pm 
Offline
Active member
It indeed is, thanks for your help!


Wiliam


Top
 Profile Send private message 
 
 Re: Convert Unix time to normal time
PostPosted: Wed Apr 24, 2013 12:50 am 
Offline
Regular
I understand getTime() is seconds since 00:00: 1/1/1970 according to the documentation, but on my machine it is 4 h earlier than new Date().time /1000. new Date() seems correct. getTime isn't. It isn't a time zone issue (I'm in EDT so UTC would be 4 h later than Date().time). The reason I'm interested is to look in data.properties at the launch.lasttime value to see how long user has been away. I can hard code the 4-h difference, but I would like to understand it. Is there something about getTime I don't understand?


Thanks in advance


Top
 Profile Send private message 
 
 Re: Convert Unix time to normal time
PostPosted: Wed Apr 24, 2013 7:01 pm 
Offline
Site Admin
User avatar
(edit)
It is a time zone issue (the opposite of behaviour you may think about).
Avoid using new Date().time, use getTime() instead, particullary calculating a time lapse.


Top
 Profile Send private message 
 
 Re: Convert Unix time to normal time
PostPosted: Fri Apr 26, 2013 1:21 am 
Offline
Regular
You say to use getTime. Fair enough. But getTime doesn't give me the correct time when I convert back to hh:mm:ss. new Date().time does. I guess what I'm looking for is a way to load in launch.lasttime and convert that to a correct (local time) hh:mm:ss. Suggestions?

BTW Doti, thanks for the large code work around. Worked great (or as great as not having external subroutines). I've certainly learned a lot about Groovy.


Top
 Profile Send private message 
 
 Re: Convert Unix time to normal time
PostPosted: Fri Apr 26, 2013 9:05 pm 
Offline
Site Admin
User avatar
Ok, thank you, there is a bug.

It'll be corrected on the next release of SexScripts. This is very strange.
(edit:ok now)


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.