中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 12:56
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » How can I get the date and time directly under DOS without having to enter them?
Printable Version  3,881 / 7
Floor1 eidolon Posted 2003-05-12 00:00
初级用户 Posts 12 Credits 140
I use date > 1.txt
but it always requires pressing Enter. Does anyone have a better solution?
Floor2 Wengier Posted 2003-05-13 00:00
系统支持 Posts 10,521 Credits 27,736
Try:
echo.|date>1.txt
Floor3 pfox Posted 2003-05-13 00:00
银牌会员 Posts 446 Credits 1,451
The following is quoted from Wengier's post on 2003-5-13 0:02:56:
Try:
echo.|date>1.txt


That won't work. I remember that under NT, 2K, and XP you can use DATE /T to output the date; as for 9X, I don't know how to handle it.
Floor4 Wengier Posted 2003-05-13 00:00
系统支持 Posts 10,521 Credits 27,736
This does work! I just tried it a moment ago!
Floor5 pfox Posted 2003-05-14 00:00
银牌会员 Posts 446 Credits 1,451
What you get this way is not just the date, there are other characters too.
Floor6 Wengier Posted 2003-05-14 00:00
系统支持 Posts 10,521 Credits 27,736
If you only want the date and time and can't have any other characters, then programs like TAD.EXE will do. For example:

TAD "Current date: $M $d,$Y ($D)$lCurrent time: $H:$n:$s
Floor7 Roy Posted 2003-05-14 00:00
管理员 Posts 1,633 Credits 4,869
Reposted from elsewhere:
----------------------
:: Parse the current date and time into multiple variables
:: Adds a zero to %hrs% if only one digit is present
@echo off
if "%1"=="GoTo:" %1%2 (Subroutine Handler)
echo @PROMPT SET TIME=$T$_SET DATE=$D$_> %TEMP%.\T1.BAT
%COMSPEC% /e:1024 /c %TEMP%.\T1.BAT > %TEMP%.\T2.BAT
type nul> %TEMP%.\T1.BAT
for %%? in (0D 10 13 27 2A) do echo e1%%?';'>> %TEMP%.\T1.BAT
for %%? in (w q) do echo %%?>> %TEMP%.\T1.BAT
DEBUG %TEMP%.\T2.BAT nul
call %TEMP%.\T2.BAT
:: Depending on the COUNTRY command from config.sys, swapping
:: the words 'month' and 'date' in next line could be necessary
call %0 GoTo: setvars %time% %date% hrs min sec dsec day month date year
FIND "= " nul
if not errorlevel=1 set hrs=0%hrs%
for %%? in (1 2) do del %TEMP%.\T%%?.BAT
echo Hrs: %hrs%
echo Min: %min%
echo Sec: %sec%
echo DSec: %dsec%
echo Day: %day%
echo Month: %month%
echo Date: %date%
echo Year: %year%
goto EOF

:setvars
if "%1"=="GoTo:" SHIFT
SHIFT
if "%9"=="" goto eof
set %9=%1
goto setvars

:eof
Floor8 eidolon Posted 2003-05-19 00:00
初级用户 Posts 12 Credits 140
Thanks, everyone. I've already solved it. I wrote a small program with TC2, very simple.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023