代码实例
set d=%date:~0,10%
set t=%time:~0,8%
echo %d% %t%
解释
格式: %date:~x,y%以及%time:~x,y%
说明: x是开始位置,y是取得字符数
比如说我要获取完整的日期和时间,
格式: %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
结果: 20120731111039
但是如果时间早于10点,那么只显示日期不显示时间,如:20120731,如何解决呢?
格式: %date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%
结果: 20120731052539
参考:
https://blog.csdn.net/samxx8/article/details/19111241
https://blog.csdn.net/machinecat0898/article/details/7804988