user94547
user94547

Reputation:

Custom datetime format in ruby?

I am trying to output a string that represents the current date/time in a format like this "yyyyMMddHHmm". For example, "201310310759" for "7:59am on 10/31/2013".

This is what I have so far:

Date.today.to_formatted_s(:db).gsub("-","")

Upvotes: 3

Views: 691

Answers (1)

Igor S.
Igor S.

Reputation: 583

Use:

Time.now.strftime("%Y%m%d%H%M")

You can check other options here

Upvotes: 4

Related Questions