How do I go about converting this time string to an era in ruby?

How will I translate 2012-12-13T14: 43: 35.371Z in the era?

One approach that I have been considering is to separate T and Z, and then try to use the DateTime library to find a way to transform into an era. Before I went down this path, I was curious if there was a gem that I could use to do this quickly. According to the corresponding note, I will do the calculations of the time after I turn to the era.

+4
source share
3 answers

For instance:

require 'date' # as an integer: DateTime.parse('2012-12-13T14:43:35.371Z').to_time.to_i # or as a string: DateTime.parse('2012-12-13T14:43:35.371Z').strftime('%s') 
+10
source
 require "time" Time.iso8601("2012-12-13T14:43:35.371Z").to_i 
+2
source
 require "date" DateTime.parse("2012-12-13T14:43:35.371Z").strftime("%s") 

In cases where you need more control over the parsing, use strptime , which allows you to define a string that explains the format.

0
source

All Articles