Aerostack
build

datetime-format Edge Function — Utilities

Utilities

Format a date to a string using format tokens like YYYY-MM-DD HH:mm:ss with optional timezone support.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function datetime-format Format a date to a string using format tokens like YYYY-MM-DD HH:mm:ss with optional timezone support.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/datetime-format
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "datetime-format",
  args: {
    "date": null,
    "format": "example_format",
    "options": null
  }
})

datetime-format — Format dates using format tokens

Format any date or timestamp into a human-readable string using pattern tokens, with full timezone support.


API

POST /api/datetime-format

Request body

Field Type Required Default Description
date string | number ISO date string or Unix ms timestamp
format string Format pattern using tokens below
options.timezone string 'UTC' IANA timezone name

Format tokens

Token Output Example
YYYY 4-digit year 2024
MM 2-digit month 01
DD 2-digit day 15
HH 24h hours 14
mm Minutes 30
ss Seconds 45
ddd Short weekday Mon
dddd Full weekday Monday
MMM Short month Jan
MMMM Full month January

Success response (200)

{
  "success": true,
  "data": {
    "formatted": "2024-01-15 10:30:45",
    "timestamp": 1705315845000,
    "timezone": "UTC"
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing required field
INTERNAL_ERROR 500 Invalid date or timezone

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{"date": "2024-01-15T10:30:45Z", "format": "MMMM DD, YYYY"}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    date: Date.now(),
    format: 'YYYY-MM-DD HH:mm:ss',
    options: { timezone: 'America/New_York' }
  }),
});
const { data } = await response.json();
console.log(data.formatted); // "2024-01-15 05:30:45"
Direct import (Node / Bun / Deno)
import { datetimeFormat } from '@aerostack/functions/datetime-format';

const result = datetimeFormat({
  date: '2024-01-15T10:30:45Z',
  format: 'dddd, MMMM DD YYYY',
});
console.log(result.formatted); // "Monday, January 15 2024"

Use Cases

  • Displaying user-facing dates in localised formats per timezone
  • Generating date-stamped filenames (e.g. report-2024-01-15.csv)
  • Formatting timestamps for logs, notifications, or receipts

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

datetime
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More Utilities Functions

Browse Utilities Functions →

Frequently asked questions

What does the datetime-format function do? +

datetime-format is a serverless edge function for utilities automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the datetime-format function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/datetime-format ``` It will be live on Cloudflare Workers in seconds.

What runtime does datetime-format use? +

datetime-format runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the datetime-format function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.