mqscript_datetime_now
Retrieve current date and time in MQScript automation scripts for mobile device control, with customizable formatting options.
Instructions
Get current date and time
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Date format string | yyyy-MM-dd HH:mm:ss |
| resultVariable | No | Variable name to store result | now |
Implementation Reference
- src/tools/plugin-commands.ts:167-178 (handler)The async handler function that generates and returns the MQScript command for getting current datetime based on input parameters.handler: async (args: { format?: string; resultVariable?: string }) => { const { format = 'yyyy-MM-dd HH:mm:ss', resultVariable = 'now' } = args; const script = `${resultVariable} = DateTime.Now("${format}")`; return { content: [ { type: 'text', text: `Generated MQScript DateTime now command:\n\`\`\`\n${script}\n\`\`\`\n\nThis gets current time in format "${format}" and stores it in "${resultVariable}".` } ] }; }
- src/tools/plugin-commands.ts:151-166 (schema)Input schema defining optional format and resultVariable parameters for the tool.inputSchema: { type: 'object' as const, properties: { format: { type: 'string', description: 'Date format string', default: 'yyyy-MM-dd HH:mm:ss' }, resultVariable: { type: 'string', description: 'Variable name to store result', default: 'now' } }, required: [] },
- src/index.ts:64-72 (registration)Tool listing handler that exposes all tools including mqscript_datetime_now from ALL_TOOLS registry.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(ALL_TOOLS).map(tool => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema, })), }; });
- src/index.ts:75-88 (registration)Tool execution handler that looks up tool by name in ALL_TOOLS and calls its handler.server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => { const { name, arguments: args } = request.params; const tool = Object.values(ALL_TOOLS).find(t => t.name === name); if (!tool) { throw new Error(`Unknown tool: ${name}`); } try { return await tool.handler(args as any || {}); } catch (error) { throw new Error(`Error executing tool ${name}: ${error instanceof Error ? error.message : String(error)}`); } });
- src/index.ts:32-61 (registration)Central ALL_TOOLS registry where DateTimeCommands (containing mqscript_datetime_now) is spread into the tool list.const ALL_TOOLS = { // Basic Commands - 基础命令 ...TouchCommands, ...ControlCommands, ...ColorCommands, ...OtherCommands, // Standard Library - 标准库函数 ...MathFunctions, ...StringFunctions, ...TypeConversionFunctions, ...ArrayFunctions, // UI Commands - 界面命令 ...UIControlCommands, ...UIPropertyCommands, ...FloatingWindowCommands, // Extension Commands - 扩展命令 ...ElementCommands, ...DeviceCommands, ...PhoneCommands, ...SysCommands, // Plugin Commands - 插件命令 ...CJsonCommands, ...DateTimeCommands, ...FileCommands, ...TuringCommands, };