API Timestamp Examples
API Timestamp Examples: implement timestamp operations with REST API, GraphQL, and cURL examples.
API Timestamp Examples
API Timestamp Examples: implement timestamp operations with REST API, GraphQL, and cURL examples.
REST API - Express.js
Get Current Timestamp
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
Convert Unix to ISO
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
Timezone Conversion
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
API Development Tips
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
About API Timestamp Examples
Production-ready API code examples for timestamp operations
Our API timestamp examples provide comprehensive, production-ready code samples for implementing timestamp operations in REST APIs, GraphQL, and various frameworks. These examples cover Express.js, FastAPI, Spring Boot, ASP.NET, and other popular frameworks with proper error handling, validation, and security best practices.
API Development Applications
Use this tool to implement timestamp operations with REST API, GraphQL, and cURL examples. It helps developers verify time data before production. Enter a value, choose a format or timezone, and copy accurate results for logs, APIs, databases, automation, or documentation.
Example Benefits
Work faster with this tool when you implement timestamp operations with REST API, GraphQL, and cURL examples. Validation catches malformed values early, and copy-ready results prevent transcription mistakes. Browser processing keeps data on your device for repeatable checks.
Tool Features
Discover what makes this tool powerful
Easy to Use
Simple and intuitive interface for all users.
Fast Processing
Quick and efficient timestamp operations.
Accurate Results
Precise timestamp calculations and conversions.
Why Choose Our Timestamp Tools?
Professional-grade timestamp processing with enterprise-level reliability
How It Works
Simple steps to use this timestamp tool effectively
Input Your Data
Enter your timestamp or date value in the input field provided by the tool.
Select Options
Choose your preferred output format and any additional options for the conversion.
Get Results
View the converted results instantly with high accuracy and precision.
Copy and Use
Copy the results to your clipboard and use them in your applications or projects.
Related Tools
Explore more timestamp conversion and calculation tools
Related Tutorials
Practical guides for working with dates, timezones, and timestamps.