Skip to main content
Glama
DSado88

DateTime MCP Server

by DSado88

get_current_time

Retrieve the current time in customizable formats (24h, 12h, or custom) with optional seconds inclusion for accurate time-sensitive operations.

Instructions

Get only the current time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format: '24h' (HH:MM:SS), '12h' (hh:MM:SS AM/PM), or custom format24h
include_secondsNoInclude seconds in the output

Implementation Reference

  • Handler for the 'get_current_time' tool that formats the current time based on the provided format ('24h', '12h', or custom using formatDate helper) and whether to include seconds.
    case "get_current_time": {
      const format = request.params.arguments?.format || "24h";
      const includeSeconds = request.params.arguments?.include_seconds !== false;
      
      let result: string;
      
      if (format === "24h") {
        const hours = now.getHours().toString().padStart(2, '0');
        const minutes = now.getMinutes().toString().padStart(2, '0');
        const seconds = now.getSeconds().toString().padStart(2, '0');
        result = includeSeconds ? `${hours}:${minutes}:${seconds}` : `${hours}:${minutes}`;
      } else if (format === "12h") {
        let hours = now.getHours();
        const ampm = hours >= 12 ? 'PM' : 'AM';
        hours = hours % 12 || 12;
        const minutes = now.getMinutes().toString().padStart(2, '0');
        const seconds = now.getSeconds().toString().padStart(2, '0');
        result = includeSeconds ? `${hours}:${minutes}:${seconds} ${ampm}` : `${hours}:${minutes} ${ampm}`;
      } else {
        result = formatDate(now, format as string);
      }
      
      return {
        content: [{
          type: "text",
          text: result
        }]
      };
    }
  • Input schema definition for the 'get_current_time' tool as provided in the ListTools response.
    {
      name: "get_current_time",
      description: "Get only the current time",
      inputSchema: {
        type: "object",
        properties: {
          format: {
            type: "string",
            description: "Output format: '24h' (HH:MM:SS), '12h' (hh:MM:SS AM/PM), or custom format",
            default: "24h"
          },
          include_seconds: {
            type: "boolean",
            description: "Include seconds in the output",
            default: true
          }
        }
      }
    }
  • Helper function used by get_current_time (and other tools) for custom date/time formatting.
    function formatDate(date: Date, format: string): string {
      const replacements: { [key: string]: string } = {
        'YYYY': date.getFullYear().toString(),
        'MM': (date.getMonth() + 1).toString().padStart(2, '0'),
        'DD': date.getDate().toString().padStart(2, '0'),
        'HH': date.getHours().toString().padStart(2, '0'),
        'mm': date.getMinutes().toString().padStart(2, '0'),
        'ss': date.getSeconds().toString().padStart(2, '0'),
      };
      
      let result = format;
      for (const [key, value] of Object.entries(replacements)) {
        result = result.replace(new RegExp(key, 'g'), value);
      }
      
      return result;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DSado88/datetime-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server