What is strftime?
strftime is "string format time" — a C library function from POSIX that converts a date/time struct into a formatted string using percent-prefixed tokens (%Y, %m, %d, etc). It first appeared in C89 and was inherited by virtually every language that wraps the C runtime: Python (datetime.strftime), Ruby (Time#strftime), Perl, PHP (date), shell (date +"%Y-%m-%d"), PostgreSQL (to_char), and many more.
Is strftime the same in every language?
Mostly, but not exactly. The core tokens (%Y %m %d %H %M %S) are universal. Differences appear at the edges: Python supports %f (microseconds) and %z behaves slightly differently from C; Ruby adds %L (milliseconds); BSD strftime supports %+; GNU adds %N (nanoseconds). When porting a format between languages, run it through the live preview here first, then sanity-check against the target language docs.
How is strftime different from Moment.js format strings?
Moment.js uses repeated letters instead of percent escapes — YYYY for 4-digit year, MM for month, DD for day, HH for 24-hour. There is no leading %. Literal letters in a format must be wrapped in [brackets] (e.g. [Year:] YYYY). The conversion table built into this tool maps %Y→YYYY, %m→MM, %d→DD, and so on, with appropriate bracketing for literals.
What about format tokens like AM/PM?
In strftime, %p emits AM or PM (uppercase, locale-dependent). In Moment.js, A is uppercase AM/PM and a is lowercase. In date-fns, a is the AM/PM marker. To pair AM/PM with 12-hour clock you almost always want %I:%M %p — which becomes hh:mm A in Moment, hh:mm a in date-fns.
How do I escape a literal % in strftime?
Use %% — two percent signs become a single literal percent in the output. So "Battery: 87%%" produces "Battery: 87%". In Moment.js or date-fns there is no special escape because % has no meaning; just include it literally.
What is the difference between %Y and %y?
%Y is the full 4-digit year (2026); %y is the 2-digit year (26). Always prefer %Y for storage and APIs to avoid Y2K-style ambiguity. Use %y only for tight UI labels (date pickers, infographic axes) where the century is obvious from context.
Why is %V different from %U?
%V is the ISO 8601 week number — week 1 is the week containing the first Thursday of the year, weeks start on Monday, and a week always has 7 days. %U (and %W) are non-ISO week-numbering schemes that count weeks starting from the first Sunday or Monday of the year, with a possibly-partial week 0. For business reports and standards-compliant output use %V; %U / %W exist mostly for legacy compatibility.
Can I use the output for date-fns?
Yes — the bottom panel emits a date-fns-compatible string for whatever you build. Pass it directly to format(date, str) from date-fns. Note that date-fns reserves single-letter tokens (D, M, Y) for different meanings than Moment.js, so the converter uses MM/dd/yyyy rather than MM/DD/YYYY. The translation table is built around the date-fns v2+ token set.