Overview
The UNIX timestamp conversion tool can convert UNIX timestamps to standard Beijing time format, and vice versa.
About Unix timestamps
A timestamp refers to the total number of seconds from Greenwich Mean Time 00:00:00 on January 1, 1970 (08:00:00 on January 1, 1970 in Beijing) to the present.
Timestamp Conversion in Programming Languages
In many programming languages, timestamp conversion often involves converting from one form of time representation (such as a date object) to another (such as a timestamp).
Here are some examples of timestamp conversion in common programming languages:
1. JavaScript
// Get the current timestamp (in milliseconds) var timestamp = Date.now(); // Convert timestamp to date object var dateObject = new Date(timestamp); // Convert a date object to a timestamp var newTimestamp = dateObject.getTime();
2. Python
import datetime from datetime # Get the current timestamp (in seconds) timestamp = datetime.timestamp(datetime.now()) # Convert timestamp to date object date_object = datetime.fromtimestamp(timestamp) # Convert a date object to a timestamp new_timestamp = datetime.timestamp(date_object)
3. Java
import java.util.Date; // Get the current timestamp (in milliseconds) long timestamp = System.currentTimeMillis(); // Convert timestamp to date object Date dateObject = new Date(timestamp); // Convert a date object to a timestamp long newTimestamp = dateObject.getTime();
4. C# (C Sharp)
// Get the current timestamp (in seconds) long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); // Convert timestamp to date object DateTimeOffset dateObject = DateTimeOffset.FromUnixTimeSeconds(timestamp); // Convert a date object to a timestamp long newTimestamp = dateObject.ToUnixTimeSeconds();
5. PHP
// Get the current timestamp (in seconds)
$timestamp = time();
// Convert timestamp to date object
$dateObject = date("Ymd H:i:s", $timestamp);
// Convert a date object to a timestamp
$newTimestamp = strtotime($dateObject);These examples cover some commonly used timestamp conversion methods in mainstream programming languages.