Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip time zone part from Time in Ruby

How to strip time zone part from Time leaving date and time parts intact? Currently I am using strftime function. My end goal is to query MySQL with local time for sure. I should be sure that local time won't be suddenly converted to something else.

like image 371
Paul Avatar asked Nov 22 '14 22:11

Paul


People also ask

How do you parse time in Ruby?

Ruby | DateTime parse() function DateTime#parse() : parse() is a DateTime class method which parses the given representation of date and time, and creates a DateTime object. Return: given representation of date and time, and creates a DateTime object.

What does time now return in Ruby?

The now() is an inbuilt method in Ruby returns the current time.


1 Answers

You can use time.strftime('%Y-%m-%d %H:%M:%S') as used by activesupport in eg

Time.now.to_s(:db)

source

like image 163
Dimitris Zorbas Avatar answered Oct 07 '22 18:10

Dimitris Zorbas