strftime Format String Reference Guide
strftime Format String Reference Guide
In strftime, '%w' represents the weekday as a number with Sunday as the first day (0-6), while '%u' represents it with Monday as the first day (1-7). This distinction allows for flexibility when adapting to different cultural or regional norms in defining the structure of a week .
strftime uses '%C' for the century (as a two-digit zero-padded number), '%Y' for the full year with century, and '%y' for the year without century. These distinctions are necessary for determining long-term time data such as historical events versus future predictions .
In strftime, '%z' represents the time zone offset from UTC in +/-HHMM format, while '%Z' denotes the time zone name. These formats are essential for handling global time representation and ensuring that time outputs are accurately adjusted for different time zones .
The '%j' specifier in strftime returns the day of the year as a zero-padded decimal number, ranging from 001 to 366. This is useful for calculating elapsed time within a year without the need to consider month variations in days .
strftime uses '%B' for full month names (e.g., January, February) and either '%b' or '%h' for abbreviated month names (e.g., Jan, Feb). These distinctions allow for formatting flexibility depending on the space available or the formality required in the display .
strftime ensures compatibility with various cultural date formats through specifiers like '%x', '%X', '%c', and '%D' that provide national representations of date and time. For example, '%x' is for dates, '%X' for times, '%c' for date and time together, and '%D' uses 'm/d/y' format .
strftime provides macros like '%r', '%R', '%T', and '%F' for specific time and date representations. '%r' is for 12-hour time with AM/PM, '%R' for 24-hour time without seconds, '%T' for a 24-hour time including seconds, and '%F' for the date in the format 'year-month-day'. These macros simplify formatting and enhance readability by reducing the need for multiple specifiers .
In strftime, the 12-hour clock format is represented using '%I' for zero-padded numbers from 01 to 12, and '%l' for space-padded numbers from 1 to 12, where single digits are preceded by a blank .
In strftime, '%s' outputs the number of seconds since the Epoch (1970-01-01 00:00:00 UTC), facilitating precise date-time calculations and timestamp generation. This is vital for time-based operations and synchronizing time across different systems .
The '%V' format specifier in strftime represents the ISO 8601 week number of the year, where weeks start on Monday. The week containing January 1 must have four or more days in the new year to be week 1; otherwise, it's the last week of the previous year. The next week is considered week 1 of the current year .