Timestamp Converter

Timestamp and Date Conversion
Timestamp
    date
    time
      Current Unix timestamp


      A timestamp is typically a representation of a specific point in time relative to a specific start time, usually measured in seconds. It is a number representing the number of seconds that have elapsed from a fixed start time (usually January 1, 1970 UTC, also known as the UNIX epoch) to a specific time. This method of calculating timestamps is called the UNIX timestamp.

      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.