Time Utilities APIs

Collection of time-related utility endpoints for working with timestamps, dates, UUIDs, and time operations.

Timestamps

Get current Unix timestamps and time-based utilities.

https://mockly.me/timestamp
GET
cURL
JavaScript
Python
curl -X GET "https://mockly.me/timestamp"
fetch('https://mockly.me/timestamp')
    .then(response => response.json())
    .then(data => {
        console.log('Current timestamp:', data.timestamp);
        
        // Use the timestamp to calculate time elapsed
        const startTime = data.timestamp;
        
        // Later in your code
        setTimeout(() => {
        const elapsedSeconds = Math.floor(Date.now() / 1000) - startTime;
        console.log(`Time elapsed: ${elapsedSeconds} seconds`);
        }, 5000);
    });
import requests
    import time

    # Get current server timestamp
    response = requests.get('https://mockly.me/timestamp')
    data = response.json()

    server_time = data['timestamp']
    local_time = int(time.time())

    print(f"Server timestamp: {server_time}")
    print(f"Local timestamp: {local_time}")
    print(f"Difference: {abs(server_time - local_time)} seconds")
Result Preview:
{
    "timestamp": 1689422587
    }
https://mockly.me/human-time
GET
cURL
JavaScript
Python
curl -X GET "https://mockly.me/human-time"
// Get human-readable time format
    fetch('https://mockly.me/human-time')
    .then(response => response.json())
    .then(data => {
        // Update UI with readable time
        document.getElementById('current-time').textContent = data.time;
        document.getElementById('current-date').textContent = data.date;
    });
import requests

    # Get human-readable time format
    response = requests.get('https://mockly.me/human-time')
    data = response.json()

    print(f"Current time: {data['time']}")
    print(f"Current date: {data['date']}")
    print(f"Relative: {data['relative']}")
Result Preview:
{
    "time": "03:45 PM",
    "date": "Saturday, July 15, 2023",
    "relative": "just now"
    }
Date & Time

Date and time formatting with timezone support.

https://mockly.me/datetime
GET
cURL
JavaScript
Python
curl -X GET "https://mockly.me/datetime?format=human&tz=US/Pacific"
// Get formatted date in a specific timezone
    fetch('https://mockly.me/datetime?format=rfc&tz=Europe/London')
    .then(response => response.json())
    .then(data => {
        console.log('Formatted date (London time):', data.datetime);
        document.getElementById('london-time').textContent = data.datetime;
    });
import requests

    # Get dates in different formats and timezones
    formats = ['iso', 'rfc', 'human', 'short']
    timezones = ['UTC', 'US/Eastern', 'Europe/Paris']

    for fmt in formats:
        for tz in timezones:
            response = requests.get(f'https://mockly.me/datetime?format={fmt}&tz={tz}')
            data = response.json()
            print(f"{tz} time in {fmt} format: {data['datetime']}")
Result Preview (human format, UTC timezone):
{
    "datetime": "July 15, 2023 at 03:45:22 PM",
    "format": "human",
    "timezone": "UTC"
    }
https://mockly.me/countdown/{timestamp}
GET
cURL
JavaScript
Python
# Countdown to New Year 2024 (Unix timestamp: 1704067200)
    curl -X GET "https://mockly.me/countdown/1704067200"
// Countdown to a future event
    const NEW_YEARS_2024 = 1704067200; // Jan 1, 2024

    function updateCountdown() {
    fetch(`https://mockly.me/countdown/${NEW_YEARS_2024}`)
        .then(response => response.json())
        .then(data => {
        if (data.status === 'expired') {
            document.getElementById('countdown').textContent = 'Event has passed!';
            return;
        }
        
        const days = data.remaining.days;
        const hours = data.remaining.hours;
        const minutes = data.remaining.minutes;
        const seconds = data.remaining.seconds;
        
        document.getElementById('countdown').textContent = 
            `${days}d ${hours}h ${minutes}m ${seconds}s`;
        });
    }

    // Update countdown every second
    setInterval(updateCountdown, 1000);
import requests
    import time

    # Target timestamp (example: project deadline)
    PROJECT_DEADLINE = int(time.time()) + 86400 * 7  # 7 days from now

    response = requests.get(f'https://mockly.me/countdown/{PROJECT_DEADLINE}')
    data = response.json()

    if 'remaining' in data:
        rem = data['remaining']
        print(f"Time until deadline: {rem['days']} days, {rem['hours']} hours, "
            f"{rem['minutes']} minutes, {rem['seconds']} seconds")
        
        # Check if deadline is close (less than 24 hours)
        if rem['total_seconds'] < 86400:
            print("Warning: Deadline approaching soon!")
Result Preview (countdown to future date):
{
    "remaining": {
        "total_seconds": 1209600,
        "days": 14,
        "hours": 0,
        "minutes": 0,
        "seconds": 0
    },
    "target_timestamp": 1704067200,
    "current_timestamp": 1689360000
    }
UUID Generation

Generate UUIDs with various formatting options.

https://mockly.me/uuid
GET
cURL
JavaScript
Python
# Generate a v4 UUID with no hyphens
    curl -X GET "https://mockly.me/uuid?version=4&hyphens=false"
// Generate a v1 (timestamp-based) UUID in uppercase
    fetch('https://mockly.me/uuid?version=1&uppercase=true')
    .then(response => response.json())
    .then(data => {
        // Use the UUID (e.g., for a session ID or tracking ID)
        console.log('Generated UUID:', data.uuid);
        
        // Store in local storage as session identifier
        localStorage.setItem('session_id', data.uuid);
    });
import requests

    # Generate different UUID formats
    uuids = []

    # Standard v4 UUID
    response = requests.get('https://mockly.me/uuid')
    uuids.append(response.json()['uuid'])

    # Uppercase UUID without hyphens
    response = requests.get('https://mockly.me/uuid?uppercase=true&hyphens=false')
    uuids.append(response.json()['uuid'])

    # v1 UUID (timestamp-based)
    response = requests.get('https://mockly.me/uuid?version=1')
    uuids.append(response.json()['uuid'])

    print("Generated UUIDs:")
    for i, uuid in enumerate(uuids, 1):
        print(f"{i}. {uuid}")
Result Preview (v4 UUID, uppercase, with hyphens):
{
    "uuid": "A1B2C3D4-E5F6-47A8-B9C0-D1E2F3A4B5C6",
    "version": 4,
    "format": "uppercase, with hyphens"
    }
https://mockly.me/batch
POST
cURL
JavaScript
Python
curl -X POST \
    "https://mockly.me/batch" \
    -H "Content-Type: application/json" \
    -d '["timestamp", "datetime", "uuid", "human-time"]'
// Get multiple time values in a single request
    fetch('https://mockly.me/batch', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify(['timestamp', 'datetime', 'uuid', 'human-time'])
    })
    .then(response => response.json())
    .then(data => {
        console.log('Timestamp:', data.timestamp);
        console.log('Datetime:', data.datetime);
        console.log('UUID:', data.uuid);
        console.log('Human time:', data['human-time']);
        
        // Use these values in your application
        document.getElementById('timestamp').textContent = data.timestamp;
        document.getElementById('datetime').textContent = data.datetime;
        document.getElementById('uuid-value').textContent = data.uuid;
    });
import requests

    # Get multiple time values in a single request
    response = requests.post(
        'https://mockly.me/batch',
        json=['timestamp', 'datetime', 'uuid', 'human-time']
    )
    data = response.json()

    # Print the results
    print(f"Current timestamp: {data['timestamp']}")
    print(f"ISO datetime: {data['datetime']}")
    print(f"UUID: {data['uuid']}")
    print(f"Human-readable time: {data['human-time']['time']}")
    print(f"Human-readable date: {data['human-time']['date']}")
Result Preview (batch request):
{
    "timestamp": 1689422587,
    "datetime": "2023-07-15T15:49:47.582942",
    "uuid": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
    "human-time": {
        "time": "03:49 PM",
        "date": "Saturday, July 15, 2023"
    }
    }
Time Tools

Additional time-related utilities and tools.

https://mockly.me/delay/{seconds}
GET
cURL
JavaScript
Python
# Request with a 5 second delay
    curl -X GET "https://mockly.me/delay/5"
// Test loading states with delayed response
    async function testLoadingState() {
    // Show loading state
    document.getElementById('loading-indicator').style.display = 'block';
    document.getElementById('content').style.display = 'none';
    
    try {
        const startTime = Date.now();
        const response = await fetch('https://mockly.me/delay/3');
        const data = await response.json();
        const endTime = Date.now();
        
        // Hide loading state, show content
        document.getElementById('loading-indicator').style.display = 'none';
        document.getElementById('content').style.display = 'block';
        
        // Show response time
        const responseTime = endTime - startTime;
        document.getElementById('response-time').textContent = 
        `Response received after ${responseTime}ms`;
        
        console.log('Delayed response:', data);
    } catch (error) {
        console.error('Request failed:', error);
        document.getElementById('error-message').textContent = 
        'Request failed. Please try again.';
    }
    }
import requests
    import time

    def test_timeout_handling():
        print("Testing request with delay...")
        start_time = time.time()
        
        try:
            # Set a timeout shorter than the delay to test timeout handling
            response = requests.get('https://mockly.me/delay/10', timeout=5)
            response.raise_for_status()
            data = response.json()
            
            print(f"Request completed in {time.time() - start_time:.2f} seconds")
            print(f"Response: {data}")
            
        except requests.exceptions.Timeout:
            print(f"Request timed out after {time.time() - start_time:.2f} seconds")
        except requests.exceptions.RequestException as e:
            print(f"Request failed: {e}")

    # Run the test
    test_timeout_handling()
Result Preview (3 second delay):
{
    "message": "Response delayed by 3 seconds",
    "timestamp": 1689422590
    }

Interactive Demo

Try out these time utilities APIs in your projects to build clock apps, countdowns, profilers, and more.

Live Time Display

Current time: Loading...
Current date: Loading...
Unix timestamp: Loading...
Session UUID: Loading...
AI-Powered

Meet Mockly Assistant

Your AI assistant for API testing, debugging and code generation. Access the power of mockly.me directly in ChatGPT.

  • Generate code examples in your preferred language
  • Get guidance for request/response handling and formatting
  • Supercharged by ChatGPT Plus from OpenAI

"How do I send data to a POST endpoint"

"I can show you how to structure your request with headers and JSON — here's a code example..."

Powered by AI