convert_unix_to_datetime
Transform Unix timestamps into readable date/time formats, including timezone adjustments and ISO compliance, for clear time representation.
Instructions
Convert unixtime to datetime time (e.g. 1746627290 to 2025-01-01 01:01:01)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isISO | No | ||
| timezone | No | ||
| unixtime | Yes |
Implementation Reference
- src/index.ts:55-68 (handler)Handler function that converts a Unix timestamp to a formatted datetime string using dayjs, respecting timezone and optional ISO format.async ({ unixtime, timezone, isISO }) => { const currentDateTime = dayjs .unix(unixtime) .tz(getTZ(timezone)) .format(isISO ? undefined : DEFAULT_TIME_FORMAT); return { content: [ { type: "text", text: currentDateTime, }, ], }; },
- src/index.ts:50-54 (schema)Zod schema defining the input parameters: unixtime (required number), timezone (optional string), isISO (optional boolean).{ unixtime: z.number(), timezone: z.string().optional(), isISO: z.boolean().optional(), },
- src/index.ts:47-69 (registration)Registration of the 'convert_unix_to_datetime' tool with name, description, input schema, and handler function using server.tool().server.tool( "convert_unix_to_datetime", "Convert unixtime to datetime time (e.g. 1746627290 to 2025-01-01 01:01:01)", { unixtime: z.number(), timezone: z.string().optional(), isISO: z.boolean().optional(), }, async ({ unixtime, timezone, isISO }) => { const currentDateTime = dayjs .unix(unixtime) .tz(getTZ(timezone)) .format(isISO ? undefined : DEFAULT_TIME_FORMAT); return { content: [ { type: "text", text: currentDateTime, }, ], }; }, );
- src/index.ts:13-15 (helper)Helper function to get timezone, using provided or guessing with dayjs.tz.guess().const getTZ = (timezon?: string) => { return timezon || dayjs.tz.guess(); };