Reputation: 12889
I have the following code in PHP, I am trying to write the same in Ruby.
$date = new DateTime(null, new DateTimeZone("UTC"));
$created = $date->format("Y-m-d\TH:i:s\Z"); //YYYY-MM-DDTHH:mm:ss.000Z;
Where T stands for Timezone Abbreviation and Z stands for Timezone Offset in PHP (Ref: http://php.net/manual/en/function.date.php).
The sample date generated by this is 2012-09-20T15:46:22.571Z
The ruby code that I have come up with is Time.now.utc.strftime("%Y-%m-%d%Z%H:%M:%S")
but it gives the output 2012-09-20UTC00:24:57
which is close to what I am trying to get to but not exactly the same. Can anyone point me to the right direction in order to get the part with .xxxZ in the end?
Upvotes: 1
Views: 574
Reputation: 15244
Take a better look at Time#strftime Various ISO 8601 formats section and probably you will come up with:
Time.now.strftime("%F%Z%T.%LZ")
%F
For The ISO 8601 date format (%Y-%m-%d)%Z
For Time zone abbreviation name%T.%L
For Local time with decimal fraction, full stop as decimal sign (extended)Z
For the final "Z"
in time string.Upvotes: 1