DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Date Time Format In RUBY

07.07.2006
| 388294 views |
  • submit to reddit
        ------------------------------------------------------------------- Time#strftime
time.strftime( string ) => string
---------------------------------------------------------------------------------
Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string.

"
Format meaning:

  %a - The abbreviated weekday name (``Sun'')
  %A - The  full  weekday  name (``Sunday'')
  %b - The abbreviated month name (``Jan'')
  %B - The  full  month  name (``January'')
  %c - The preferred local date and time representation
  %d - Day of the month (01..31)
  %H - Hour of the day, 24-hour clock (00..23)
  %I - Hour of the day, 12-hour clock (01..12)
  %j - Day of the year (001..366)
  %m - Month of the year (01..12)
  %M - Minute of the hour (00..59)
  %p - Meridian indicator (``AM''  or  ``PM'')
  %S - Second of the minute (00..60)
  %U - Week  number  of the current year,
          starting with the first Sunday as the first
          day of the first week (00..53)
  %W - Week  number  of the current year,
          starting with the first Monday as the first
          day of the first week (00..53)
  %w - Day of the week (Sunday is 0, 0..6)
  %x - Preferred representation for the date alone, no time
  %X - Preferred representation for the time alone, no date
  %y - Year without a century (00..99)
  %Y - Year with century
  %Z - Time zone name
  %% - Literal ``%'' character

   t = Time.now
   t.strftime("Printed on %m/%d/%Y")   #=> "Printed on 04/09/2003"
   t.strftime("at %I:%M%p")            #=> "at 08:56AM"
"
    

Comments

Abdel Zoo replied on Wed, 2014/10/22 - 7:04pm

  Thanks for your efforts  g9g 2014 games

Jak Down replied on Tue, 2014/10/21 - 6:46am

 
There are many people who desire to build muscles on their bodies. You might be one of them and you are probably wondering why your daily workout is not effective click

cris ma replied on Tue, 2014/06/10 - 1:01pm

 LED lights nowadays are a matter of great deal of thought for practicality reason. Electric companies are charging more and one thing is sure, they will continue to raise the rate.

LED Lights For Home

Alex Jee replied on Tue, 2014/05/13 - 10:55am in response to: Ahsan Gill

A great website accompanying fascinating also lone stuff what more would you demand.http://www.wmaker.net/regarder-film/ 

Alex Jee replied on Mon, 2014/02/24 - 12:06pm in response to: Ahsan Gill

I visualize the greatest texts on your blog further I certainly affection lesson them.
Transporting a horse 

Ahsan Gill replied on Tue, 2014/02/04 - 2:02pm

Wow! I really appreciate the thought that you put into this article. This topic has been something I have been looking into for a few hours and your post is one of the best I have read. bodyguar services in rio de jeneiro bodyguard services in sao paulo bodyguard services in sochi bodyguard services in russia

Engr Ubaid Masood replied on Mon, 2014/02/03 - 1:21am

Hi,

This is great informative and helpful blog , thanks for sharing

Regards,

 

Construction Site in London 

hire domestic workers in london 

Hire security in london 

www.ibodyguardlondon.com

Alex Jee replied on Sat, 2014/03/01 - 1:05pm in response to: Ahsan Gill

Your blogs furthermore entire split matter are so interesting besides moneymaking it prepares me happen retreat most afresh.
solda mig usada 

Ankur Sharma replied on Wed, 2013/11/20 - 1:58am

LED Bulbs
The energy efficient nature of LEDs allows them to produce brighter light than other types of www.myledlight.co.uk bulbs while using less energy.

Ankur Sharma replied on Wed, 2013/11/13 - 5:16am

 Design is the fundamental soul of a man-made creation that ends up expressing itself in successive outer layers of the product or service. The iMac is not just the color or translucence or the shape of the shell. Energy

Ankur Sharma replied on Fri, 2013/10/18 - 4:49am

 seo group of jhansi, social media optimization, link building,social bookmarking,article submission services,<a href="http://onlineseojhansi.blogspot.in/">best services in jhansi</a>online seo in jhansi,link building services,best services in jhansi
<a href="http://seogroupofjhansi.blogspot.in/">Link building</a>

Ankur Sharma replied on Thu, 2013/10/17 - 2:29am

 auto body paint NY, clearcoat, clearcoat NY, Car Paint, Auto body Paint, Toners from Silver Sails Paints at AutoBodyPaintStore.com Auto Body Paint

Ankur Sharma replied on Thu, 2013/10/17 - 1:20am

 Die größten Katalog von Objekten mit direkten Kontakten zu Eigentümern und sicherlich billigsten Unterkünfte rund um die Küste von Kroatien Ferienhaus Kroatien

Andreea Socolov replied on Sun, 2013/10/13 - 8:18am

How about the employee time clocks at TimeClockeShop.com? Aren't these a good choice as well? There's too much technology..

Ankur Sharma replied on Thu, 2013/10/10 - 6:58am

  Thanks for taking the time to discuss this, I feel strongly about it and love reading more on this topic. If possible, as you gain knowledge, would you mind updating your blog with more information? It is top female combat boots on the market 

Ankur Sharma replied on Mon, 2013/10/07 - 12:26am

 

It is our good luck that I found this meaning ful article to study because there is a lots of topics to study what can increase our social sites knowledge blinds bolton

Ankur Sharma replied on Sun, 2013/10/06 - 1:34am

 

Your post is very exciting and informative. I am planning to decide on a career move and this has helped me with one aspect. Thanks man!
hindi shayari

Ankur Sharma replied on Fri, 2013/10/04 - 1:45am

 

This web page may be a walk-through like the knowledge you wished about it and didn’t know who to ask. Glimpse here, and you’ll definitely discover it. short term loans

Ankur Sharma replied on Tue, 2013/10/01 - 11:50am

 Oh where am I gonna find a free feeling
Oh the one I've always wanted to know
Where I am not afraid of revealing, oh no
I'll show whatever I want whenever I want
Well I've done an awful lot of concealing

matta

Ankur Sharma replied on Tue, 2013/10/01 - 5:31am

Ferienhaus Kroatien
Die größten Katalog von Objekten mit direkten Kontakten zu Eigentümern und sicherlich billigsten Unterkünfte rund um die Küste von Kroatien

Ankur Sharma replied on Mon, 2013/09/30 - 3:44am

 kanhagranites is a granite exporters in india , professional company involved in the processing, granite slabs wholesale and retailing of Indian Granite.granite slabs

Sadia Sulaman replied on Tue, 2014/07/01 - 1:32am in response to: Ankur Sharma

 Your blog has some of the most fascinating information! I've read several pages here and I just had to comment and let you know that I thought you've been doing a great job here.

BlogHuts

Ankur Sharma replied on Thu, 2013/09/26 - 4:30am

 Really nice designer platform, in my opinion, definitely something of interest to me. Best Backlinks Provider

Ankur Sharma replied on Mon, 2013/09/09 - 11:37pm

 Daily Audio Bible - listen online, on demand topics and episodes, location, contact, schedule and broadcast information.audio bible

Ankur Sharma replied on Mon, 2013/09/09 - 1:10am

auto body paint ny and Auto Paint, Toners from Silver Sails Paints in business profiles,
contact information, services and more.auto body paint ny

Ankur Sharma replied on Sun, 2013/09/08 - 2:43am

 kanhagranites is a wholesale and retailing in india.granite slabs

Ankur Sharma replied on Fri, 2013/08/30 - 10:13am

 Thank you for taking the time to publish this information very helpful!I've been looking for books of this nature for a way too long. I'm just glad that I found yours. Looking forward for your next post.

hackett shop

Ankur Sharma replied on Fri, 2013/08/23 - 2:48am

 I appreciate the work of all people who share information with others. Great Blog! kamagra

Ankur Sharma replied on Thu, 2013/08/22 - 6:19am

 Your Land Rover Range Rover is a tough vehicle but when it comes time to buy parts, you’ll always want to consider buying genuine Land parts We have Pioneered many Land Rover Parts to make life better for the Land Rover ecift 

Ankur Sharma replied on Mon, 2013/08/19 - 4:35am

 System that can help got a superb blogging site   .I shall be excited about more related matters. i see you bought honestly extremely helpful themes , i'll be always taking a look at your web page thank you. karmaloop rep code

Ankur Sharma replied on Sat, 2013/08/17 - 11:45pm

 You may write about the offers on the blog. You could broadcast it’s super. Your blog assessment should escalate your opt-ins. karmaloop rep code  

Ankur Sharma replied on Sat, 2013/08/17 - 3:38am

 

I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. karmaloop promo code

Ahsan Gill replied on Wed, 2013/01/09 - 5:38am

Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.armstrong security  armstrong security  armstrong security  armstrong security   armstrong security

Gabriel Falkenberg replied on Wed, 2008/12/10 - 5:56pm

Since I always seem to return to this page whenever I want to format dates in ruby I'd like to add the following snippet here: Time.now.strftime("%Y-%m-%d %H:%M") => "2010-02-27 15:00"

Jeremy Weiskotten replied on Wed, 2007/04/25 - 3:45pm

Check out http://strfti.me for a very readable online reference and sandbox where you can experiment with different strftime format strings.

Snippets Manager replied on Mon, 2008/07/14 - 9:18pm

%e actually gives you the day of the month, with a space instead of a 0. %l give you the hours of the day with a space instead of zero. %g gives you the last two digits of the year 2-digit year (00-99) ...and you know what - just see the C reference for a complete listing: http://linux.die.net/man/3/strftime Also note: In ruby, you can prefix with minus to format out leading zeros, for eg: "%-d/%-m/%y"

Gabriel Falkenberg replied on Wed, 2008/12/10 - 5:56pm

And off course with seconds: Time.now.strftime("%Y-%m-%d %H:%M:%S") => "2010-03-12 16:36:33"

Snippets Manager replied on Sun, 2012/05/06 - 1:28pm

Such a great way to describe the topic i really like your writing abilities and Thanks for sharing such a informative knowledge Security Companies London

Snippets Manager replied on Wed, 2012/03/14 - 4:07am

It was an excellent way opted by you to describe your ideas with us.I would love to read more about your newly updated posts. ======================================================================================= ibm certifications|| ibm certification|| ibm certification exams||

Bernd Juenger replied on Sun, 2007/06/17 - 10:16am

Great, somebody already put it in cheat sheet (or vice versa). Thanks anyway! => http://cheat.errtheblog.com/s/strftime/

Snippets Manager replied on Mon, 2008/07/14 - 9:18pm

%e gives you the day of the month without the leading zero (0).