ISO8601 Colon Bar Rails

In Rails 4 / Ruby, how can I return an alphanumeric string from an ISO timestamp?

Time.now.getutc.iso8601 #=> 2015-10-08T16:12:51Z

I would like him to return the same thing as above, without -and without :.
#=> 20151008T121251Z

+4
source share
1 answer

You can use the strftime method to format your time in any way. It uses a string as a parameter that determines the format of the output.

In fact, the iso8601 method uses strftime internally with "%FT%T"as a format string.

To get the desired result, you can use this format string:

Time.now.getutc.strftime('%Y%m%dT%H%M%SZ')

, strftime .

+4

Source: https://habr.com/ru/post/1610809/


All Articles