Loading...
Loading...
Comprehensive API timestamp examples for Express.js, FastAPI, Spring Boot, and more. Production-ready REST API, GraphQL, and cURL examples with proper timestamp handling.
REST API, GraphQL, and cURL examples for timestamp operations
GET /api/timestamp/current
// Express.js endpoint
app.get('/api/timestamp/current', (req, res) => {
  const timestamp = {
    unix: Math.floor(Date.now() / 1000),
    unixMs: Date.now(),
    iso: new Date().toISOString(),
    utc: new Date().toUTCString(),
    local: new Date().toString()
  };
  
  res.json({
    success: true,
    data: timestamp,
    generatedAt: new Date().toISOString()
  });
});
// Response example:
{
  "success": true,
  "data": {
    "unix": 1640995200,
    "unixMs": 1640995200000,
    "iso": "2022-01-01T00:00:00.000Z",
    "utc": "Sat, 01 Jan 2022 00:00:00 GMT",
    "local": "Fri Dec 31 2021 16:00:00 GMT-0800 (PST)"
  },
  "generatedAt": "2022-01-01T00:00:00.000Z"
}Get current timestamp in multiple formats
POST /api/timestamp/convert
// Express.js conversion endpoint
app.post('/api/timestamp/convert', (req, res) => {
  const { timestamp, from, to } = req.body;
  
  try {
    let date;
    
    // Parse input based on format
    if (from === 'unix') {
      date = new Date(timestamp * 1000);
    } else if (from === 'unixMs') {
      date = new Date(timestamp);
    } else if (from === 'iso') {
      date = new Date(timestamp);
    }
    
    // Convert to target format
    let result;
    switch (to) {
      case 'unix':
        result = Math.floor(date.getTime() / 1000);
        break;
      case 'unixMs':
        result = date.getTime();
        break;
      case 'iso':
        result = date.toISOString();
        break;
      case 'utc':
        result = date.toUTCString();
        break;
      default:
        result = date.toString();
    }
    
    res.json({
      success: true,
      input: { timestamp, from, to },
      result: result,
      convertedAt: new Date().toISOString()
    });
  } catch (error) {
    res.status(400).json({
      success: false,
      error: 'Invalid timestamp format',
      message: error.message
    });
  }
});Convert between different timestamp formats
POST /api/timestamp/timezone
// Express.js timezone conversion
app.post('/api/timestamp/timezone', (req, res) => {
  const { timestamp, fromTz, toTz } = req.body;
  
  try {
    const date = new Date(timestamp);
    
    // Convert to target timezone
    const options = {
      timeZone: toTz,
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      hour12: false
    };
    
    const converted = date.toLocaleString('en-CA', options);
    const isoConverted = new Date(converted + 'Z').toISOString();
    
    res.json({
      success: true,
      input: {
        timestamp,
        fromTz: fromTz || 'UTC',
        toTz
      },
      result: {
        formatted: converted,
        iso: isoConverted,
        unix: Math.floor(new Date(converted).getTime() / 1000)
      }
    });
  } catch (error) {
    res.status(400).json({
      success: false,
      error: 'Invalid timezone or timestamp',
      message: error.message
    });
  }
});Convert timestamps between different timezones
Always validate timestamp inputs and handle parsing errors gracefully
Use consistent timestamp formats across your API (prefer ISO 8601)
Include timezone information when dealing with user-specific times
Consider rate limiting for timestamp conversion endpoints
Document your timestamp formats clearly in API documentation
Test API endpoints in a development environment before production use
Replace example URLs with your actual API endpoints
用于时间戳操作的生产就绪API代码示例
我们的API时间戳示例提供全面的生产就绪代码示例,用于在REST API、GraphQL和各种框架中实现时间戳操作。这些示例涵盖Express.js、FastAPI、Spring Boot、ASP.NET和其他流行框架,具有适当的错误处理、验证和安全最佳实践。
API时间戳示例通过提供经过测试的安全代码模式来加速开发。这些示例帮助开发者在不同编程语言和框架中实现一致的时间戳操作。
生产就绪代码,多框架支持,全面的错误处理,安全最佳实践,cURL命令示例,GraphQL模式,以及现代Web应用程序的集成模式。
Discover what makes this tool powerful
Complete API timestamp examples for Express.js, FastAPI, Spring Boot, ASP.NET, and more popular frameworks. Production-ready code with proper timestamp handling and validation.
Professional REST API and GraphQL timestamp examples following industry standards. Complete with cURL commands, request/response formats, and error handling patterns.
Real-world API timestamp examples with comprehensive error handling, input validation, timezone support, and security best practices for production environments.
All API timestamp examples are ready to copy and integrate into your projects. Complete with dependencies, imports, and configuration examples.
API timestamp examples include security best practices, input sanitization, rate limiting, and protection against common timestamp-related vulnerabilities.
Optimized API timestamp examples with caching strategies, efficient database queries, and performance best practices for high-traffic applications.
专业级时间戳处理,企业级可靠性
简单步骤有效使用此时间戳工具
在工具提供的输入字段中输入您的时间戳或日期值。
选择您首选的输出格式和任何转换的附加选项。
以高准确性和精度即时查看转换结果。
将结果复制到剪贴板,并在您的应用程序或项目中使用。
Explore more timestamp conversion and calculation tools