Thursday, May 02, 2013

Date Time Formatting in Ruby and Ruby on Rails


In develop any Ruby on Rails application, most of time we need to time calculation and different types of date time. Bellow i describe different types ruby date time format and rails date time format.

So open your rails console and test this bellow examples -

Rails Date Time helpers.



now = Time.now        #=> 2013-04-30 00:14:38 +0600
now + 10.seconds      #=> 2013-04-30 00:14:48 +0600
now + 10.minutes      #=> 2013-04-30 00:24:38 +0600
now + 1.hours         #=> 2013-04-30 01:14:38 +0600
now + 1.days          #=> 2013-05-01 00:14:38 +0600
now + 1.weeks         #=> 2013-05-07 00:14:38 +0600
now + 1.months        #=> 2013-05-30 00:14:38 +0600
now + 1.years         #=> 2014-04-30 00:14:38 +0600
now - 1.years         #=> 2012-04-30 00:14:38 +0600

Rails Date Time Calculations.


now.beginning_of_day   #=> 2013-04-30 00:00:00 +0600
now.beginning_of_week  #=>2013-04-29 00:00:00 +0600
now.beginning_of_month #=>2013-04-01 00:00:00 +0600
now.yesterday          #=>2013-04-29 00:14:38 +0600
now.prev_month         #=> 2013-03-30 00:14:38 +0600
now.prev_year          #=> 2012-04-30 00:14:38 +0600
now.end_of_day         #=>2013-04-30 23:59:59 +0600
now.end_of_week        #=> 2013-05-05 23:59:59 +0600
now.end_of_month       #=> 2013-04-30 23:59:59 +0600
now.end_of_year        #=> 2013-12-31 23:59:59 +0600
now.tomorrow           #=>2013-05-01 00:14:38 +0600
now.next_month         #=>2013-05-30 00:14:38 +0600
now.next_year          #=>2014-04-30 00:14:38 +0600

Ruby Date Time Formatting.


now = Time.now                          #=>2013-04-30 00:38:26 +0600
now.strftime("%m/%d/%Y")                #=> "04/30/2013"
now.strftime("%I:%M%p")                 #=> "12:38AM"
now.strftime("%Y-%d-%m")                #=>"2013-30-04"
now.strftime("%Y-%m-%d")                #=>"2013-04-30"
now.strftime("%y-%m-%d")                #=>"13-04-30"
now.strftime("%d %B %Y")                #=>"30 April 2013"
now.strftime("%d %b %Y")                #=>"30 Apr 2013"
now.strftime("%A, %d %b %Y")            #=>"Tuesday, 30 Apr 2013"
now.strftime("%a %d %b %Y")             #=>"Tue 30 Apr 2013"
now.strftime("%Y-%m-%d %H:%M:%S %p")    #=>"2013-04-30 00:38:26 AM"
now.strftime("%Y-%m-%d %H:%M:%S %p %z") #=>"2013-04-30 00:38:26 AM +0600"

Rails Date Time Formatting.


now = Time.now          #=>2013-04-30 00:58:05 +0600
now.to_s(:db)           #=> "2013-04-30 00:58:05"
now.to_s(:number)       #=> "20130430005805"
now.to_s(:time)         #=> "00:58"
now.to_s(:short)        #=> "30 Apr 00:58"
now.to_s(:long)         #=> "April 30, 2013 00:58"
now.to_s(:long_ordinal) #=>"April 30th, 2013 00:58"


Monday, October 31, 2011

HTML Tutorial part - 7 ( Text formatting tags - part -3)


HTML Allows various type of Text formatting tags.

HTML Tutorial in Bangla.




Bellow describe this :

<marquee> : This tag is used for indicating any scrolling type content.
<Blink> : This tag is used for indicating any blinking header type content.
<address> : This tag is used for indicating an address. If you write any address type content in your HTML document, then you can use this address tag.
<center>:This tag is used to center-align HTML elements.
<blockquote> : This tag is used for indicating long quotations.
<q> : This tag is used for indicating short quotations. This tags including content show will including a short quotations. 



Example of Above tags -


<!--textformat.html-->
<html>
<head>
  <title>HTML Text Formatting tags part - one</title>
</head>
<body>
<marquee> This is scroling text style..</marquee>
<blink> BD News.</blink>
<pre><p> This         is paragraph
            format.</p>
</pre>
<center><p>Contact Me.</p>
<address><p> Sahidur Rahman Suman<br />
Dhaka - 1207<br />
Bangladesh<br />
</p></address>
</center>

<p>Here is a long quatation.<p>

<blockquote>
HTML stands for Hypertext Markup Language, is the common markup language for creating or describing a web pages. It is not a programming language, it is a markup language.HyperText is a system for linking together concepts within and among documents.
</blockquote>
<br />
<p> Here comes a short quatation: <q> This is a short quatation.</q></p>
</body>
</html>


Output will be shown as bellow -

This is scroling text style..
BD News.
This      is paragraph 
   format.


Contact Me.
Sahidur Rahman Suman

Dhaka - 1207

Bangladesh



Here is a long quatation.
HTML stands for Hypertext Markup Language, is the common markup language for creating or describing a web pages. It is not a programming language, it is a markup language.HyperText is a system for linking together concepts within and among documents.

Here comes a short quatation: This is a short quatation.

Saturday, October 22, 2011

HTML Tutorial part - 6 ( Text formatting tags - part - 2)


HTML Allows various type of Text formatting tags.

HTML Tutorial in Bangla.




Bellow describe this :

<ins> : This tag content style is insert style. if you want to show that you insert some text in your web pages that time you can use this element. 
<del> : This tag content style is delete style. If you want to show that you delete some text from your web pages that you can use this element.
<strike> : This tag enclosed text is displayed as like del element style.
<cite>: This tag content style is citation style. This tags enclosed text is displayed with Italic too. This tag use for write any quotation in web document.
<code> : This tag content style is computer code style. If you want to write any computer programming source code in your web pages that time you can use this element.
<samp> : This tag content style is sample style.
<var> : This tag content style is variable style.
<tt> : This tag content style is Tele Style.
<sub> : This tag content style is Subscript style. It will be use when you write any subscript type content like chemical name or atomic name or chemical equation.
  <sup> :  This tag content style is Superscript style. It will be use when you write any Subscript type content  like mathematical equations.


Example of Above tags -


<!--textformat.html-->
<html>
<head>
  <title>HTML Text Formatting tags part - one</title>
</head>
<body>
    <ins> This is insert style</ins><br />
    <del> This is delete style</del><br />
    <strike> This is strikethrough Style</strike><br />
    <cite> This is citation style.</cite><br />
    <code> This is computer code style</code><br />
    <samp> This is sample style</samp><br />
    <var> This is variable style</var><br />
    <tt> This is telestyle</tt><br />
    Subscript - H<sub>2</sub><br />
    Superscript - a<sup>2</sup>+2ab+ b<sup>2</sup>
</body>
</html>


Output will be shown as bellow -

This is insert style

This is delete style

This is strikethrough Style

This is citation style.

This is computer code style

This is sample style

This is variable style

This is telestyle

Subscript - H2

Superscript - a2+2ab+ b2