# Reverting date from Time.to\_s

**URL:** <https://www.ruby-forum.com/t/reverting-date-from-time-to-s/185560>\
**Category:** Ruby\
**Created:** [March 22, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/reverting-date-from-time-to-s/185560 "2010-03-22T19:06:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![utsavgupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4af34b/32.png) [@utsavgupta](https://www.ruby-forum.com/u/utsavgupta)\
**Post date:** [March 22, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/reverting-date-from-time-to-s/185560/1 "2010-03-22T19:06:04Z")

</div>

I receive the dates from Twitter in the following format “Mon Mar 22  
04:42:17 +0000 2010”

Now how can I create a time object from this string… ie Obj.year=2010,  
Obj.month=3… etc etc

Regards

Utsav Gupta

---

<div class="post-metadata">

**Author:** ![utsavgupta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4af34b/32.png) [@utsavgupta](https://www.ruby-forum.com/u/utsavgupta)\
**Post date:** [March 22, 2010, 7:20pm UTC](https://www.ruby-forum.com/t/reverting-date-from-time-to-s/185560/2 "2010-03-22T19:20:14Z")

</div>

On Mar 22, 2010, at 1:06 PM, Utsav Gupta wrote:

> I receive the dates from Twitter in the following format “Mon Mar 22  
> 04:42:17 +0000 2010”
> 
> Now how can I create a time object from this string… ie Obj.year=2010,  
> Obj.month=3… etc etc

Quite simple.

cremes$ irb  
ruby-1.9.1-p378 \> require ‘time’  
=\> true  
ruby-1.9.1-p378 \> s = “Mon Mar 22 04:42:17 +0000 2010”  
=\> “Mon Mar 22 04:42:17 +0000 2010”  
ruby-1.9.1-p378 \> t = Time.parse s  
=\> 2010-03-21 23:42:17 -0500  
ruby-1.9.1-p378 \> t.month  
=\> 3  
ruby-1.9.1-p378 \> t.year  
=\> 2010

Note that Time.parse creates your time object with the local timezone.  
You can still access zulu time by using the #utc method on that object.

cr
