# Assign Time

**URL:** <https://www.ruby-forum.com/t/assign-time/133902>\
**Category:** Rails\
**Created:** [April 4, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/assign-time/133902 "2008-04-04T19:45:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 4, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/assign-time/133902/1 "2008-04-04T19:45:21Z")

</div>

How do you assign time to a variable.  
ie:

9:30 AM

party = cccc.to\_time ?

how about military time?

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 4, 2008, 8:33pm UTC](https://www.ruby-forum.com/t/assign-time/133902/2 "2008-04-04T20:33:28Z")

</div>

rashantha wrote:

> How do you assign time to a variable.

Google and/or use ri on your command line for Time#now

> ie:
> 
> 9:30 AM
> 
> party = cccc.to\_time ?

party = Time.parse(‘9:30 am’). But I’m not sure what it will do about  
the date.

In Rails, 9.hours + 30.minutes might also work, to get the seconds from  
midnite.

> how about military time?

Time.now.strftime(’%H:%M’).

Google strftime to learn the correct codes to put in there.

–  
Phlip
