在不同日期格式下批处理输出自定义格式的日期和时间
- font size decrease font size increase font size
在Windows系统中有不同的语言版本和时区设置。有时,由于业务的需求,我们需要生成“年月日”格式的日期格式目录,然后在该目录中生成时间格式的文件,用来记录系统当前时间的日志信息。
系统日期有yy-mm-dd,mm-dd-yy以及dd-mm-yy三种格式,这样导致了使用的不方便。下面介绍几种实现方法:
- 有 人通过预先修改windows注册表将日期改成yy-mm-dd格式然后通过发出命令:c:\> echo %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%这种该注册表的方法显然不是很可取。
- 还有人通过vbs来实现,制作成批处理文件内容如下:@echo off
echo wscript.echo year(date) ^& right(”0″ ^& month(date),2) ^& right(”0″ ^& day(date),2) ^& right(”0″ ^& hour(time),2) ^& right(”0″ ^& minute(time),2)>%tmp%\temp1.vbs
cscript /nologo %tmp%\temp1.vbs
del %tmp%\temp1.vbs这种使用script的方式也不是很好。
- 我认为最好的方式是,通过批处理中的for语句进行系统日期格式的判断,然后进行处理。批处理文件内容如下:
@ECHO OFF
ECHO. |DATE > temp1
FOR /F “eol=T tokens=5 delims=() ” %%i in (temp1) do set date_format=%%i
FOR /F “eol=E tokens=5,6,7,8 delims=/- ” %%a in (temp1) do (
IF /I %date_format% EQU mm-dd-yy ( set month=%%a
set day=%%b
set year=%%c
set week=%%d )
IF /I %date_format% EQU dd-mm-yy ( set day=%%a
set month=%%b
set year=%%c
set week=%%d )
IF /I %date_format% EQU yy-mm-dd ( set year=%%a
set month=%%b
set day=%%c
set week=%%d ) )ECHO. |TIME > temp2
FOR /F “eol=E tokens=5-8 delims=:. ” %%A in (temp2) do ( set hour=%%A
set minute=%%B
set second=%%C
set hundredth=%%D )
REM TIME format 08:10:00 PM, it means 20:10:00
REM IF %meridiem% EQU PM SET /A %%hour%%=%%hour%%+12SET current_date=%year%%month%%day%
SET current_time=%hour%%minute%%second%%hundredth%IF EXIST temp1 DEL /Q temp1
IF EXIST temp2 DEL /Q temp2ECHO Current date = %current_date%
ECHO Current time = %current_time%MKDIR %current_date%
ECHO. > %current_date%\%current_time%.log
( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169 | ||||
---|---|---|---|---|
Call Stack | ||||
# | Time | Memory | Function | Location |
1 | 0.0001 | 405704 | {main}( ) | .../index.php:0 |
2 | 0.0764 | 1324592 | Joomla\CMS\Application\SiteApplication->execute( ) | .../index.php:49 |
3 | 0.0764 | 1324592 | Joomla\CMS\Application\SiteApplication->doExecute( ) | .../CMSApplication.php:196 |
4 | 0.2135 | 2983296 | Joomla\CMS\Application\SiteApplication->dispatch( ) | .../SiteApplication.php:233 |
5 | 0.2148 | 3008360 | Joomla\CMS\Component\ComponentHelper::renderComponent( ) | .../SiteApplication.php:194 |
6 | 0.2159 | 3063688 | Joomla\CMS\Component\ComponentHelper::executeComponent( ) | .../ComponentHelper.php:377 |
7 | 0.2160 | 3080744 | require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ) | .../ComponentHelper.php:402 |
8 | 0.2251 | 3224832 | K2ControllerItem->execute( ) | .../k2.php:64 |
9 | 0.2251 | 3224832 | K2ControllerItem->display( ) | .../BaseController.php:710 |
10 | 0.2315 | 3493912 | K2ControllerItem->display( ) | .../item.php:78 |
11 | 0.2315 | 3493912 | K2ControllerItem->display( ) | .../controller.php:19 |
12 | 0.2330 | 3512432 | Joomla\CMS\Cache\Controller\ViewController->get( ) | .../BaseController.php:663 |
13 | 0.2399 | 3532848 | K2ViewItem->display( ) | .../ViewController.php:102 |
14 | 0.2988 | 4077664 | K2ViewItem->display( ) | .../view.html.php:742 |
15 | 0.2988 | 4077664 | K2ViewItem->loadTemplate( ) | .../HtmlView.php:230 |
16 | 0.3003 | 4252384 | include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ) | .../HtmlView.php:701 |
- Published in Server 2008
- Read 3108 times
( ! ) Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478 | ||||
---|---|---|---|---|
Call Stack | ||||
# | Time | Memory | Function | Location |
1 | 0.0001 | 405704 | {main}( ) | .../index.php:0 |
2 | 0.0764 | 1324592 | Joomla\CMS\Application\SiteApplication->execute( ) | .../index.php:49 |
3 | 0.0764 | 1324592 | Joomla\CMS\Application\SiteApplication->doExecute( ) | .../CMSApplication.php:196 |
4 | 0.2135 | 2983296 | Joomla\CMS\Application\SiteApplication->dispatch( ) | .../SiteApplication.php:233 |
5 | 0.2148 | 3008360 | Joomla\CMS\Component\ComponentHelper::renderComponent( ) | .../SiteApplication.php:194 |
6 | 0.2159 | 3063688 | Joomla\CMS\Component\ComponentHelper::executeComponent( ) | .../ComponentHelper.php:377 |
7 | 0.2160 | 3080744 | require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ) | .../ComponentHelper.php:402 |
8 | 0.2251 | 3224832 | K2ControllerItem->execute( ) | .../k2.php:64 |
9 | 0.2251 | 3224832 | K2ControllerItem->display( ) | .../BaseController.php:710 |
10 | 0.2315 | 3493912 | K2ControllerItem->display( ) | .../item.php:78 |
11 | 0.2315 | 3493912 | K2ControllerItem->display( ) | .../controller.php:19 |
12 | 0.2330 | 3512432 | Joomla\CMS\Cache\Controller\ViewController->get( ) | .../BaseController.php:663 |
13 | 0.2399 | 3532848 | K2ViewItem->display( ) | .../ViewController.php:102 |
14 | 0.2988 | 4077664 | K2ViewItem->display( ) | .../view.html.php:742 |
15 | 0.2988 | 4077664 | K2ViewItem->loadTemplate( ) | .../HtmlView.php:230 |
16 | 0.3003 | 4252384 | include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ) | .../HtmlView.php:701 |