Imran Imran - 3 months ago 10x
Ruby Question

Convert String to DateTime Ruby

I have a string

extracted from json response. How can convert it to Time or DateTime?

I tried"2015-11-01T10:00:00.00+08:00")
its returning
2015-01-01 00:00:00 +0530
, clearly the date is changed here and time too.

require 'date'

▶ Date.parse "2015-11-01T10:00:00.00+08:00"
#⇒ #<Date: 2015-11-01 ((2457328j,0s,0n),+0s,2299161j)>

▶ DateTime.parse "2015-11-01T10:00:00.00+08:00"
#⇒ #<DateTime: 2015-11-01T10:00:00+08:00 ((2457328j,7200s,0n),+28800s,2299161j)>