samedi 30 mai 2015

Rails Convert UNIX timestamp to SQL DateTime

I have timestamp as "1432927800000"

I want to save it in DateTime column of MySQL. (SQL DateTime column stores date in this format : 2010-06-24 11:30:00)

I have tried

uTime = params[:fromDate] #contains "1432927800000"
Date.new(uTime).to_formatted_s(:db) #Comparison of String with 0 failed.
DateTime.strptime("1318996912",'%s') #Give weird date: Wed, 03 Sep 47377 12:00:00 +0000
Date.parse(uTime).to_s(:db) #Invalid Date

I am expecting 2015-5-30 1:00:00 from "1432927800000"

Aucun commentaire:

Enregistrer un commentaire