API Documentation

Provides complete REST API for developers to integrate timestamp conversion functionality in their applications

Basic Information

API Base URL
https://timestamptodate.com/api/v1
Data Format
JSON
Character Encoding
UTF-8
HTTP Methods
GET, POST
Timestamp to Date
Date to Timestamp
Current Time
Batch Conversion
History
Format List

Timestamp to Date

Convert timestamp to specified format date string

Interface Information

URL GET /api/v1/timestamp
Description Convert timestamp to specified format date string
Parameters
  • timestamp (Required) - Timestamp parameter
  • format (Optional) - Format parameter (optional)

Request Example

GET https://timestamptodate.com/api/v1/timestamp?timestamp=1640995200&format=Y-m-d

Response Example

{
  "success": true,
  "timestamp": 1640995200,
  "timestamp_ms": 1640995200000,
  "results": [
    {
      "format": "Y-m-d",
      "description": "指定格式",
      "date": "2022-01-01"
    }
  ]
}

docs_timestamp_to_multiple_formats

Convert timestamp to multiple common date formats

Interface Information

URL GET /api/v1/timestamp/formats
Description Convert timestamp to multiple common date formats
Parameters
  • timestamp (Required) - Timestamp parameter

Request Example

GET https://timestamptodate.com/api/v1/timestamp/formats?timestamp=1640995200

Response Example

{
  "success": true,
  "timestamp": 1640995200,
  "timestamp_ms": 1640995200000,
  "results": [
    {
      "format": "Y-m-d H:i:s",
      "description": "Standard Format",
      "date": "2022-01-01 00:00:00"
    },
    {
      "format": "Y年m月d日 H:i:s",
      "description": "Chinese Format",
      "date": "2022年01月01日 00:00:00"
    },
    {
      "format": "D, d M Y H:i:s",
      "description": "RFC 2822",
      "date": "Sat, 01 Jan 2022 00:00:00"
    }
  ]
}

Date to Timestamp

Convert date string to timestamp

Interface Information

URL GET /api/v1/date
Description Convert date string to timestamp
Parameters
  • date (Required) - Date parameter

Supported Date Formats

  • Y-m-d H:i:s (Standard format)
  • Y-m-d (Short date)
  • m/d/Y H:i:s (US format)
  • d/m/Y H:i:s (European format)
  • Y-m-dTH:i:sP (ISO 8601)

Request Example

GET https://timestamptodate.com/api/v1/date?date=2022-01-01

Response Example

{
  "success": true,
  "date": "2022-01-01",
  "timestamp": 1640995200,
  "timestamp_ms": 1640995200000
}

Get Current Timestamp

Get current timestamp and multiple format representations

Interface Information

URL GET /api/v1/current
Description Get current timestamp and multiple format representations
Parameters
  • ms (Optional) - parameter_return_milliseconds

Request Example

GET https://timestamptodate.com/api/v1/current

Response Example

{
  "success": true,
  "timestamp": 1698886400,
  "timestamp_ms": 1698886400000,
  "date": "2023-11-01 12:00:00",
  "date_ms": "2023-11-01 12:00:00.123",
  "iso": "2023-11-01T12:00:00+08:00",
  "rfc": "Wed, 01 Nov 2023 12:00:00 +0800",
  "timezone": "Asia/Shanghai",
  "utc_offset": "+08:00"
}

Batch Conversion

Batch convert multiple timestamps

Interface Information

URL POST /api/v1/batch
Description Batch convert multiple timestamps
docs_request_body
  • timestamps (Required) - Timestamp array parameter
  • format (Optional) - Format parameter (optional)

Request Example

POST https://timestamptodate.com/api/v1/batch
Content-Type: application/json

{
  "timestamps": [1640995200, 1641081600, 1641168000],
  "format": "Y-m-d"
}

Response Example

{
  "success": true,
  "total": 3,
  "results": [
    {
      "input": "1640995200",
      "success": true,
      "data": {
        "format": "Y-m-d",
        "description": "format_batch_conversion",
        "date": "2022-01-01"
      },
      "error": null
    },
    {
      "input": "1641081600",
      "success": true,
      "data": {
        "format": "Y-m-d",
        "description": "format_batch_conversion",
        "date": "2022-01-02"
      },
      "error": null
    },
    {
      "input": "1641168000",
      "success": true,
      "data": {
        "format": "Y-m-d",
        "description": "format_batch_conversion",
        "date": "2022-01-03"
      },
      "error": null
    }
  ]
}

Get Conversion History

Get conversion history records

Interface Information

URL GET /api/v1/history
Description Get conversion history records
Parameters
  • limit (Optional) - parameter_record_limit

Request Example

GET https://timestamptodate.com/api/v1/history?limit=10

Response Example

{
  "success": true,
  "history": [
    {
      "id": 1,
      "timestamp_input": "1640995200",
      "timestamp_value": 1640995200,
      "date_result": "2022-01-01 00:00:00",
      "format": "Y-m-d H:i:s",
      "ip_address": "127.0.0.1",
      "user_agent": "Mozilla/5.0...",
      "created_at": "2023-11-01 12:00:00"
    }
  ]
}

Get Common Formats

Get system preset common date formats

Interface Information

URL GET /api/v1/formats
Description Get system preset common date formats
Parameters docs_no_parameters

Request Example

GET https://timestamptodate.com/api/v1/formats

Response Example

{
  "success": true,
  "formats": [
    {
      "id": 1,
      "name": "ISO 8601",
      "format": "Y-m-d\\TH:i:sP",
      "description": "format_international_standard",
      "is_active": 1,
      "sort_order": 1
    },
    {
      "id": 2,
      "name": "format_chinese_date",
      "format": "Y年m月d日 H:i:s",
      "description": "format_chinese_datetime",
      "is_active": 1,
      "sort_order": 2
    }
  ]
}

Get Timezone List

Get system supported timezone list

Interface Information

URL GET /api/v1/timezones
Description Get system supported timezone list
Parameters docs_no_parameters

Request Example

GET https://timestamptodate.com/api/v1/timezones

Response Example

{
  "success": true,
  "timezones": [
    {
      "value": "Asia/Shanghai",
      "label": "Asia/Shanghai",
      "offset": "+08:00"
    },
    {
      "value": "UTC",
      "label": "UTC",
      "offset": "+00:00"
    }
  ]
}

Error Handling

API uses standard HTTP status codes and unified error response format

HTTP Status Codes

  • 200 - Request successful
  • 400 - Request parameter error
  • 404 - Interface does not exist
  • 500 - Server internal error

Error Response Format

{
  "success": false,
  "error": "错误信息"
}

Common Errors

Error Message Explanation
Please provide timestamp parameter Timestamp parameter missing
Invalid timestamp Invalid timestamp
Please provide date parameter Date parameter missing
Invalid date format Invalid date format
Please provide timestamp array Timestamp array missing for batch conversion

Usage Examples

JavaScript

// 时间戳转日期
fetch('https://timestamptodate.com/api/v1/timestamp?timestamp=1640995200')
  .then(response => response.json())
  .then(data => {
    if (data.success) {
      console.log(data.results[0].date);
    }
  });

// 批量转换
fetch('https://timestamptodate.com/api/v1/batch', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    timestamps: [1640995200, 1641081600]
  })
})
  .then(response => response.json())
  .then(data => {
    if (data.success) {
      data.results.forEach(result => {
        console.log(result.input, result.success ? result.data.date : result.error);
      });
    }
  });

PHP

// 时间戳转日期
$response = file_get_contents('https://timestamptodate.com/api/v1/timestamp?timestamp=1640995200');
$data = json_decode($response, true);

if ($data['success']) {
    echo $data['results'][0]['date'];
}

// 批量转换
$data = [
    'timestamps' => [1640995200, 1641081600],
    'format' => 'Y-m-d'
];

$options = [
    'http' => [
        'method' => 'POST',
        'header' => 'Content-Type: application/json',
        'content' => json_encode($data)
    ]
];

$context = stream_context_create($options);
$response = file_get_contents('https://timestamptodate.com/api/v1/batch', false, $context);
$result = json_decode($response, true);

Python

import requests
import json

# 时间戳转日期
response = requests.get('https://timestamptodate.com/api/v1/timestamp?timestamp=1640995200')
data = response.json()

if data['success']:
    print(data['results'][0]['date'])

# 批量转换
data = {
    'timestamps': [1640995200, 1641081600],
    'format': 'Y-m-d'
}

response = requests.post('https://timestamptodate.com/api/v1/batch', json=data)
result = response.json()

if result['success']:
    for item in result['results']:
        if item['success']:
            print(item['input'], item['data']['date'])