datetime-format Edge Function — Utilities
UtilitiesFormat a date to a string using format tokens like YYYY-MM-DD HH:mm:ss with optional timezone support.
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.
npx aerostack add navin/datetime-format Use with AI Assistants
MCPConnect 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.
{
"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({
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
Tags
Publisher
@navin verified
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 →datetime-add
by @navin
Add or subtract a duration from a date, supporting units from milliseconds to years with correct month-end handling.
datetime-business-hours
by @navin
Check if a datetime falls within business hours and return the next opening time.
datetime-diff
by @navin
Calculate the difference between two dates in specified units (ms, seconds, minutes, hours, days, weeks, months, years).
datetime-duration-format
by @navin
Format a duration in milliseconds to a human-readable string with long, short, or compact styles.
datetime-parse
by @navin
Parse a date string or unix timestamp to a normalised Unix millisecond timestamp and ISO string.
datetime-relative
by @navin
Format a date as a relative time string like '2 hours ago' or 'in 3 days' using Intl.RelativeTimeFormat.
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.