Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                

Using strftime

Introduction

The strftime format is the standard date formatting for UNIX. It's used in C, Ruby, and more.

Unix date

date +%Y-%m-%d
date +'%A, %B %e, %Y'

The POSIX date command uses the same format codes as strftime.

See: POSIX strftime

Ruby

Time.now.strftime('%H:%M')

Ruby's Time#strftime accepts the same codes.

See: Time#strftime

Format codes

Presets

Date

ExampleOutput
%m/%d/%Y06/05/2013
%F2013-06-05
%b %e %aJun 5 Wed

Time

ExampleOutput
%I:%M %p11:05 PM
%T23:05:00

See: strftime

Date tokens

TokenOutputDescription
%aSunWeekday, short
%ASundayWeekday, full
%w0..6Weekday, Sunday is 0
%y13Year, two digits
%Y2013Year, four digits
%bJanMonth name, short
%BJanuaryMonth name, full
%m01..12Month, two digits
%d01..31Day, two digits
%e1..31Day, space-padded

See: strftime

Time tokens

TokenOutputDescription
%l1Hour, 12-hour, space-padded
%H00..23Hour, 24-hour, two digits
%I01..12Hour, 12-hour, two digits
%M00..59Minute, two digits
%S00..60Second, two digits
%pAMMeridiem
%ZUTCZone name
%z+0000Numeric offset
%j001..366Day of year
%s1370473500Unix timestamp, seconds
%%%Literal percent sign

See: strftime

0 Comments for this cheatsheet. Write yours!