比如时间是2024/1/1
我想得到 2024/01/01
要怎么写???
string.foring("%02d",1)
string.foring("%02f",1)
顶一下~~~~~
自己实现一个格式化函数
https://www.npmjs.com/package/format
var format = require('format')
, printf = format.printf
, vsprintf = format.vsprintf
// or if you want to keep it old school
, sprintf = format
// Print 'hello world'
printf('%s world', 'hello')
var what = 'life, the universe, and everything'
format('%d is the answer to %s', 42, what)
// => '42 is the answer to life, the universe, and everything'
vsprintf('%d is the answer to %s', [42, what])
// => '42 is the answer to life, the universe, and everything'
先转换为时间戳,然后再转换为字符串格式
或者先转换为字符串数组,然后再合并并格式化