Both are date and string conversions. Which is which? Eliminate the hesitation.
① strftime: "date" → "character string" ② strptime: "character string" → "date"
-The "f" of strftime is regarded as "from". └ str from time: Character string from time (date)
・ Strptime is not "from" └ str time: string to date
・ "P" of strptime is "purse" └ purse: analyze └ What needs to be parsed is a string (date data is typed)
- There are various theories about the meaning of "f" and "p". I'm writing something that fits nicely.
** Reference ** -Strftime: How to change the date format (date → character string) -Strptime: How to convert character string data to date (character string → date)
** ■ Frequently used specifiers **
Specifier | meaning |
---|---|
%Y | 4 digits in the Christian era(yyyy) |
%y | 2 digits in the Christian era(yy) |
%m | Month (with 0 padding) |
%d | Day (with 0 padding) |
%H | Hours (24 hours,0 filled) |
%I | Time (12 hours,0 filled) |
%M | Minutes (0 padded) |
%S | Seconds (with 0 padding) |
Specifier | meaning |
---|---|
%#m | Month (no 0 padding) |
%#d | Day (no 0 padding) |
%#H | Hours (24 hours,0 not filled) |
%#I | Time (12 hours,0 not filled) |
%#M | Minutes (no 0 padding) |
%#S | Seconds (without zero padding) |
mac: Add "-"
Specifier | meaning |
---|---|
%-m | Month (no 0 padding) |
%-d | Day (no 0 padding) |
%-H | Hours (24 hours,0 not filled) |
%-I | Time (12 hours,0 not filled) |
%-M | Minutes (no 0 padding) |
%-S | Seconds (without zero padding) |
Specifier | meaning |
---|---|
%f | Microseconds(1~6 digits) |
%a | Day of the week(Shortened form) |
%A | Day of the week(full) |
%w | Day of the week(0~6「0:Sun ~ 6:Month") |
%j | date(1-366 days, 0 fill) |
%W | Week number(0~53, 0 fill) |
%U | %Same as W |
%% | "" As a character string%」 |