Convert Date to Timestamp
PHP
// Convert human-readable date to Unix timestamp
strtotime("November 25, 2025");
// Result: 1764050732
// Alternative formats
strtotime("11/25/2025");
strtotime("+10 days"); // 10 days from now
// Object-oriented approach
$date = new DateTime('11/25/2025');
echo $date->format('U'); // Unix timestamp
// With timezone
$date = new DateTime('11/25/2025', new DateTimeZone('UTC'));
$timestamp = $date->getTimestamp();JavaScript
// Convert date string to Unix timestamp
const myDate = new Date("November 25, 2025 08:05:32");
const myEpoch = Math.floor(myDate.getTime() / 1000);
console.log(myEpoch); // 1764050732
// Using Date.parse()
const timestamp = Math.floor(Date.parse("2025-11-25") / 1000);
// From individual components
const date = new Date(2025, 10, 25, 8, 5, 32);
const epoch = Math.floor(date.getTime() / 1000);
// Current timestamp
const now = Math.floor(Date.now() / 1000);Python
import calendar
import time
from datetime import datetime
# Convert date string to Unix timestamp
date_string = '2025-11-25 08:05:32'
timestamp = calendar.timegm(time.strptime(date_string, '%Y-%m-%d %H:%M:%S'))
print(timestamp) # 1764050732
# Using datetime module
dt = datetime(2025, 11, 25, 8, 5, 32)
timestamp = int(dt.timestamp())
# Current timestamp
import time
current_timestamp = int(time.time())Java
import java.time.*;
import java.time.format.DateTimeFormatter;
// Convert date string to Unix timestamp
String dateString = "2025-11-25 08:05:32";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = LocalDateTime.parse(dateString, formatter);
long timestamp = dateTime.atZone(ZoneId.of("UTC")).toEpochSecond();
System.out.println(timestamp); // 1764050732
// From individual components
LocalDateTime dt = LocalDateTime.of(2025, 11, 25, 8, 5, 32);
long epochSecond = dt.toEpochSecond(ZoneOffset.UTC);
// Current timestamp
long currentTimestamp = Instant.now().getEpochSecond();C#
using System;
// Convert DateTime to Unix timestamp
DateTime dateTime = new DateTime(2025, 11, 25, 8, 5, 32, DateTimeKind.Utc);
long timestamp = ((DateTimeOffset)dateTime).ToUnixTimeSeconds();
Console.WriteLine(timestamp); // 1764050732
// From string
DateTime parsedDate = DateTime.Parse("2025-11-25 08:05:32");
long unixTime = ((DateTimeOffset)parsedDate.ToUniversalTime()).ToUnixTimeSeconds();
// Current timestamp
long currentTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
// Alternative using TimeSpan
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long timestamp2 = (long)(dateTime - epoch).TotalSeconds;Go
package main
import (
"fmt"
"time"
)
func main() {
// Convert date to Unix timestamp
layout := "2006-01-02 15:04:05"
dateString := "2025-11-25 08:05:32"
t, _ := time.Parse(layout, dateString)
timestamp := t.Unix()
fmt.Println(timestamp) // 1764050732
// From individual components
date := time.Date(2025, time.Month(11), 25, 8, 5, 32, 0, time.UTC)
unixTime := date.Unix()
// Current timestamp
currentTimestamp := time.Now().Unix()
fmt.Println(currentTimestamp)
}Swift
import Foundation
// Convert date string to Unix timestamp
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
if let date = dateFormatter.date(from: "2025-11-25 08:05:32") {
let timestamp = Int(date.timeIntervalSince1970)
print(timestamp) // 1764050732
}
// From Date components
let calendar = Calendar.current
let components = DateComponents(year: 2025, month: 11, day: 25,
hour: 8, minute: 5, second: 32)
if let date = calendar.date(from: components) {
let unixTime = Int(date.timeIntervalSince1970)
}
// Current timestamp
let currentTimestamp = Int(Date().timeIntervalSince1970)Rust
use chrono::{DateTime, Utc, NaiveDateTime, TimeZone};
// Convert date string to Unix timestamp
let date_str = "2025-11-25 08:05:32";
let naive_dt = NaiveDateTime::parse_from_str(date_str, "%Y-%m-%d %H:%M:%S").unwrap();
let dt: DateTime<Utc> = Utc.from_utc_datetime(&naive_dt);
let timestamp = dt.timestamp();
println!("{}", timestamp); // 1764050732
// From individual components
let dt = Utc.ymd(2025, 11, 25).and_hms(8, 5, 32);
let unix_time = dt.timestamp();
// Current timestamp
let now = Utc::now();
let current_timestamp = now.timestamp();
// Using std::time
use std::time::{SystemTime, UNIX_EPOCH};
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let timestamp_std = duration.as_secs();