[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Time.format

nornagon

7/17/2005 4:54:00 PM

Hi all.

If there's one thing I miss about PHP, it must be date(). PHP's date()
function is similar in purpose to Time.strftime, only with a whole
slew of extra formatting options. For more info, see
http://ph...

However, ruby seems to have no equivalent function. So I made my own.
(Well, not entirely. I copied it from
http://simon.incutio.com/archive/2003/10/07/da...)

Attached. It works like this:

Time.now.format "jS M Y" # => "18th Jul 2005"

I'd like to have this in the core, if people like it.
--
- nornagon


5 Answers

nornagon

7/17/2005 4:56:00 PM

0

On 7/18/05, nornagon <nornagon@gmail.com> wrote:
> [snip]

Eep. When I said "attached", I meant "attached to the next post."

--
- nornagon

nornagon

7/17/2005 5:17:00 PM

0

Okay, it's three in the morning and I'm not quite on my toes. Here it
is again with a few more things implemented.
--
- nornagon

vanekl

7/18/2005 3:40:00 AM

0

nobu.nokada

7/18/2005 4:13:00 AM

0

Hi,

At Mon, 18 Jul 2005 02:16:47 +0900,
nornagon wrote in [ruby-talk:148492]:
> Okay, it's three in the morning and I'm not quite on my toes. Here it
> is again with a few more things implemented.

$ ri Time#strftime
---------------------------------------------------------- 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"

--
Nobu Nakada


Jesus Christ the Holy Cunt Fucker

10/3/2009 11:11:00 AM

0

On Oct 2, 4:34 pm, wakalukong <wakaluko...@gmail.com> wrote:
> On Oct 2, 3:56 pm, "Komin the almighy fucking failure analyst from
> CUNT_bodia, fake Khmer aka fake wakalukong and monster"
>
> <real_ko...@hotmail.com> wrote:
> > This guy fucking Jap Komin is fucking crazy. Just beware of him here.