CTIME Formatting Guide
Complete guide to CTIME timestamp formatting with 30+ directives, examples, and real-world use cases for logs, APIs, emails, and databases.
Overview
CTIME formatting provides a way to format timestamps using directives similar to the Unix strftime function. This guide explains how to use CTIME format strings with practical examples.
Basic Concept
CTIME formatting works by replacing format directives (special character sequences starting with %) with their corresponding components from a date/time value. For example:
%Yrepresents the full 4-digit year%mrepresents the month (zero-padded)%drepresents the day of month (zero-padded)
Common Timestamp Format Examples
ISO 8601 Format
Format: %F %T
Example: 2025-12-23 14:30:45Equivalent to: %Y-%m-%d %H:%M:%S
US Short Date Format
Format: %m/%d/%y
Example: 12/23/25Same as the %D or %x directive
Full Date and Time
Complete date and time representation
12-Hour Time with AM/PM
24-Hour Time Only
Equivalent to: %H:%M
For 24-hour time with seconds:
Equivalent to: %H:%M:%S
RFC 2822 Style
Log Timestamp Format
Verbose Format
Directive Reference
Year
%Y
Year, zero-padded (0001-9999)
2025
%y
Year, last two digits
25
Month
%m
Month as decimal (01-12)
12
%o
Month space-padded (1-12)
12
%q
Month unpadded (1-12)
12
%B
Full month name
December
%b, %h
Abbreviated month
Dec
Day of Month
%d
Day zero-padded (01-31)
23
%e
Day space-padded (1-31)
23
%g
Day unpadded (1-31)
23
Weekday
%A
Full weekday name
Monday
%a
Abbreviated weekday
Mon
Hour (24-hour clock)
%H
Hour zero-padded (00-23)
14
Hour (12-hour clock)
%I
Hour zero-padded (01-12)
02
%l
Hour unpadded (0-12)
2
%p
Locale AM/PM
PM
%P
Locale am/pm
pm
Minute
%M
Minute zero-padded (00-59)
30
Second
%S
Second zero-padded (00-59)
45
Fractional Seconds
%L
Millisecond (000-999)
500
%f
Microsecond (000000-999999)
500000
%s
Nanosecond (000000000-999999999)
500000000
Timezone
%Z
Timezone name/abbreviation
MST
%z
UTC offset (±HHMM[SS[.ffffff]])
-0700
%w
UTC offset with seconds
-070000
%i
UTC offset (short form)
-07
%j
UTC offset with colons
-07:00
%k
UTC offset full format
-07:00:00
Composite Formats
%D, %x
Short date (MM/DD/YY)
%m/%d/%y
%F
ISO 8601 date (YYYY-MM-DD)
%Y-%m-%d
%T, %X
ISO 8601 time (HH:MM:SS)
%H:%M:%S
%R
24-hour time (HH:MM)
%H:%M
%r
12-hour time with AM/PM
HH:MM:SS am/pm
%c
Full date and time
Mon Jan 02 15:04:05 2006
Special Characters
%n
Newline character
%t
Horizontal tab character
%%
Literal % sign
Practical Usage Tips
Combining Directives: You can mix multiple directives in a single format string
Padding Variations: Different directives provide different padding options for the same component
Timezone Information: Include timezone data for complete timestamp information
Readable Formats: Use full month and weekday names for human-readable timestamps
Millisecond Precision: Include
%Lfor application logs
Example Use Cases
Server Log Entry
API Response Timestamp
Email Header Format
Database Audit Log
User-Friendly Display
Last updated
Was this helpful?