Skip to main content
Glama
guangxiangdebizi

FinanceMCP

current_timestamp

Retrieve the current timestamp in the China time zone (GMT+8), formatted as datetime, date, time, Unix timestamp, or readable text for accurate time-based financial data processing.

Instructions

获取当前东八区(中国时区)的时间戳,包括年月日时分秒信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNo时间格式,可选值:datetime(完整日期时间,默认)、date(仅日期)、time(仅时间)、timestamp(Unix时间戳)、readable(可读格式)

Implementation Reference

  • The core handler function for the 'current_timestamp' tool. It computes the current time in China timezone (UTC+8), supports formatting options (datetime, date, time, timestamp, readable), includes Chinese weekday, returns structured MCP content with markdown, and handles errors.
    async run(args?: { format?: string }) {
      try {
        // 获取当前UTC时间
        const now = new Date();
        
        // 转换为东八区时间(UTC+8)
        const chinaTime = new Date(now.getTime() + (8 * 60 * 60 * 1000));
        
        const format = args?.format || 'datetime';
        
        // 格式化时间函数
        const formatNumber = (num: number): string => num.toString().padStart(2, '0');
        
        const year = chinaTime.getUTCFullYear();
        const month = formatNumber(chinaTime.getUTCMonth() + 1);
        const day = formatNumber(chinaTime.getUTCDate());
        const hour = formatNumber(chinaTime.getUTCHours());
        const minute = formatNumber(chinaTime.getUTCMinutes());
        const second = formatNumber(chinaTime.getUTCSeconds());
        
        // 星期几
        const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
        const weekday = weekdays[chinaTime.getUTCDay()];
        
        let result: string;
        
        switch (format) {
          case 'date':
            result = `${year}-${month}-${day}`;
            break;
          case 'time':
            result = `${hour}:${minute}:${second}`;
            break;
          case 'timestamp':
            result = Math.floor(chinaTime.getTime() / 1000).toString();
            break;
          case 'readable':
            result = `${year}年${month}月${day}日 ${weekday} ${hour}时${minute}分${second}秒`;
            break;
          case 'datetime':
          default:
            result = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
            break;
        }
        
        return {
          content: [
            {
              type: "text",
              text: `## 🕐 当前东八区时间\n\n格式: ${format}\n时间: ${result}\n\n时区: 东八区 (UTC+8)\n星期: ${weekday}\n\n---\n\n*时间戳获取于: ${year}-${month}-${day} ${hour}:${minute}:${second}*`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text", 
              text: `❌ 获取时间戳时发生错误: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Input schema for the current_timestamp tool, defining an optional 'format' parameter as string with description of supported formats.
    parameters: {
      type: "object",
      properties: {
        format: {
          type: "string",
          description: "时间格式,可选值:datetime(完整日期时间,默认)、date(仅日期)、time(仅时间)、timestamp(Unix时间戳)、readable(可读格式)"
        }
      }
  • src/index.ts:228-231 (registration)
    Registration/dispatch in the CallToolRequestSchema handler: extracts 'format' argument and calls the tool's run method.
    case "current_timestamp": {
      const format = request.params.arguments?.format ? String(request.params.arguments.format) : undefined;
      return await timestampTool.run({ format });
    }
  • Compact version of the core handler function for HTTP server, identical logic to stdio version but simplified response without error handling or full weekday in output.
    async run(args?: { format?: string }) {
      const now = new Date();
      const chinaTime = new Date(now.getTime() + (8 * 60 * 60 * 1000));
      const format = args?.format || 'datetime';
      const pad = (n: number) => n.toString().padStart(2, '0');
      const y = chinaTime.getUTCFullYear();
      const m = pad(chinaTime.getUTCMonth() + 1);
      const d = pad(chinaTime.getUTCDate());
      const hh = pad(chinaTime.getUTCHours());
      const mm = pad(chinaTime.getUTCMinutes());
      const ss = pad(chinaTime.getUTCSeconds());
      const weekdays = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
      const wd = weekdays[chinaTime.getUTCDay()];
      let result = `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
      if (format === 'date') result = `${y}-${m}-${d}`;
      if (format === 'time') result = `${hh}:${mm}:${ss}`;
      if (format === 'timestamp') result = Math.floor(chinaTime.getTime()/1000).toString();
      if (format === 'readable') result = `${y}年${m}月${d}日 ${wd} ${hh}时${mm}分${ss}秒`;
      return { content: [{ type: 'text', text: `## 🕐 当前东八区时间\n\n格式: ${format}\n时间: ${result}\n星期: ${wd}` }] };
  • Dispatch case in the HTTP /mcp POST tools/call handler for current_timestamp.
    case 'current_timestamp':
      return await timestampTool.run({ format: args?.format ? String(args.format) : undefined });

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/guangxiangdebizi/FinanceMCP'

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