Common Timestamp Formats:
Unix Timestamp:
• Seconds since January 1, 1970 UTC
• Example: 1640995200 (Jan 1, 2022 00:00:00 UTC)
• Range: 1970-2038 (32-bit), 1970-292 billion years (64-bit)
Unix Timestamp (Milliseconds):
• Milliseconds since January 1, 1970 UTC
• Example: 1640995200000
• Common in JavaScript: Date.now()
ISO 8601:
• International standard format
• Example: 2022-01-01T00:00:00.000Z
• Formats: YYYY-MM-DDTHH:mm:ss.sssZ
RFC 2822:
• Email and HTTP standard
• Example: Sat, 01 Jan 2022 00:00:00 GMT
• Used in HTTP headers and email
Local Formats:
• US: MM/DD/YYYY HH:mm:ss
• European: DD/MM/YYYY HH:mm:ss
• ISO Date: YYYY-MM-DD HH:mm:ss
Programming Languages:
• JavaScript: new Date().getTime()
• Python: time.time(), datetime.now()
• Java: System.currentTimeMillis()
• C#: DateTimeOffset.UtcNow.ToUnixTimeSeconds()
• PHP: time(), date()
• Go: time.Now().Unix()
Timestamp Examples:
Common Timestamps:
• Unix Epoch: 0 (Jan 1, 1970 00:00:00 UTC)
• Y2K: 946684800 (Jan 1, 2000 00:00:00 UTC)
• 9/11: 1000166400 (Sep 11, 2001 08:46:40 UTC)
• iPhone Launch: 1172707200 (Jan 9, 2007 18:00:00 UTC)
• Bitcoin Genesis: 1231006505 (Jan 3, 2009 18:15:05 UTC)
JavaScript Examples:
const now = Date.now(); // milliseconds
const timestamp = Math.floor(Date.now() / 1000); // seconds
const date = new Date(1640995200 * 1000);
Python Examples:
import time
import datetime
timestamp = time.time()
dt = datetime.datetime.fromtimestamp(1640995200)
iso = datetime.datetime.now().isoformat()
Database Examples:
-- MySQL
SELECT UNIX_TIMESTAMP(), FROM_UNIXTIME(1640995200);
-- PostgreSQL
SELECT EXTRACT(EPOCH FROM NOW()), TO_TIMESTAMP(1640995200);
-- SQLite
SELECT strftime('%s', 'now'), datetime(1640995200, 'unixepoch');
API Examples:
// REST API with timestamps
{
"created_at": 1640995200,
"updated_at": "2022-01-01T00:00:00Z",
"expires": 1672531200
}
Log File Examples:
[1640995200] INFO: Application started
2022-01-01 00:00:00 ERROR: Connection failed
Jan 1 00:00:00 server: Process completed
Timezone Information:
UTC (Coordinated Universal Time):
• Primary time standard
• No daylight saving time
• Used in databases and APIs
• GMT equivalent for practical purposes
Major Timezones:
• EST/EDT: UTC-5/-4 (Eastern Time)
• CST/CDT: UTC-6/-5 (Central Time)
• MST/MDT: UTC-7/-6 (Mountain Time)
• PST/PDT: UTC-8/-7 (Pacific Time)
• GMT/BST: UTC+0/+1 (London)
• CET/CEST: UTC+1/+2 (Central Europe)
• JST: UTC+9 (Japan, no DST)
• AEST/AEDT: UTC+10/+11 (Eastern Australia)
Daylight Saving Time:
• Spring Forward: Clocks move ahead 1 hour
• Fall Back: Clocks move back 1 hour
• Not all regions observe DST
• Dates vary by country/region
Best Practices:
• Store timestamps in UTC
• Convert to local time for display
• Use timezone-aware libraries
• Handle DST transitions carefully
• Use ISO 8601 for data exchange
Common Pitfalls:
• Assuming local timezone
• Ignoring DST transitions
• Mixing timezone-aware and naive datetimes
• Using local time for calculations
• Not handling leap seconds
Programming Tips:
• JavaScript: Use Date.toISOString()
• Python: Use datetime.utcnow()
• Java: Use Instant.now()
• Always specify timezone explicitly
• Test with different timezones