Formatting

To format a date provide a string beginning with + .

Format specifiers (format string starts with +)

Specifier

Description

Values/Example

Day

%a

weekday, abbreviated

Sun

%A

weekday, full

Sunday

%d

day of the month (dd), zero padded

01

%e

day of the month (dd)

1

%j

day of year, zero padded

001-366

%u

day of week starting with Monday (1), i.e. mtwtfss

7

%w

day of week starting with Sunday (0), i.e. smtwtfs

0

Week

%U

week number Sunday as first day of week

01–53

%W

week number Monday as first day of week

01–53

%V

week of the year

01–53

Month

%m

mm month

05

%h

Mon

May

%b

Mon, locale's abbreviated

May

%B

locale's full month, variable length

May

Year

%y

yy two digit year

00–99

%Y

ccyy year

2011

%g

2-digit year corresponding to the %V week number

 

%G

4-digit year corresponding to the %V week number

 

Century

%C

cc century

00–99

Date

%D

mm/dd/yy

05/1/11

%x

locale's date representation (mm/dd/yy)

05/1/2011

%F

%Y-%m-%d

2011-05-1

Hours

%l (Lowercase L)

hour (12 hour clock)

9

%I (Uppercase I)

hour (12 hour clock) zero padded

09

%k

hour (24 hour clock)

9

%H

hour (24 hour clock) zero padded

09

%p

locale's upper case AM or PM (blank in many locales)

AM

%P

locale's lower case am or pm

am

Minutes

%M

MM minutes

39

Seconds

%s

seconds since 00:00:00 1970-01-01 UTC (Unix epoch)

1304242752

%S

SS second

00–60
(The 60 is necessary to accommodate a leap second)

%N

nanoseconds

000000000–999999999

Time

%r

hours, minutes, seconds (12-hour clock)

09:39:12 AM

%R

hours, minutes (24 hour clock)

hh:mm e.g. 09:39

%T

hours, minutes, seconds (24-hour clock)

09:39:12

%X

locale's time representation (%H:%M:%S)

 

Date and Time

%c

locale's date and time

Sat Nov 04 12:02:33 EST 1989

Time zone

%z

-zzzz RFC-822 style numeric timezone

-0500

%Z

time zone (e.g., EDT) nothing if no time zone is determinable

EST

參考:http://en.wikipedia.org/wiki/Date_(Unix)

    全站熱搜

    mitblog 發表在 痞客邦 留言(0) 人氣()