China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 10:17
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can I get the date and time directly under DOS without having to enter them? View 3,704 Replies 7
Original Poster Posted 2003-05-12 00:00 ·  中国 河南 洛阳 中移铁通
初级用户
Credits 140
Posts 12
Joined 2003-03-31 00:00
23-year member
UID 1336
Gender Male
Status Offline
I use date > 1.txt
but it always requires pressing Enter. Does anyone have a better solution?
Floor 2 Posted 2003-05-13 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Try:
echo.|date>1.txt
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 3 Posted 2003-05-13 00:00 ·  中国 广东 汕头 电信
银牌会员
★★★
Credits 1,451
Posts 446
Joined 2002-10-20 00:00
23-year member
UID 29
Gender Male
Status Offline
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.
Floor 4 Posted 2003-05-13 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
This does work! I just tried it a moment ago!
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 5 Posted 2003-05-14 00:00 ·  中国 广东 汕头 电信
银牌会员
★★★
Credits 1,451
Posts 446
Joined 2002-10-20 00:00
23-year member
UID 29
Gender Male
Status Offline
What you get this way is not just the date, there are other characters too.
Floor 6 Posted 2003-05-14 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
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
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 7 Posted 2003-05-14 00:00 ·  中国 香港
管理员
★★★★
專業島民
Credits 4,869
Posts 1,633
Joined 2002-12-10 00:00
23-year member
UID 465
Gender Male
Status Offline
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
我的網站:http://mw16.2ya.com/ 我的網誌: http://scrappedblog.blogspot.com/
~
我的Winamp正在播放的歌曲:
Floor 8 Posted 2003-05-19 00:00 ·  中国 河南 洛阳 中移铁通
初级用户
Credits 140
Posts 12
Joined 2003-03-31 00:00
23-year member
UID 1336
Gender Male
Status Offline
Thanks, everyone. I've already solved it. I wrote a small program with TC2, very simple.
Forum Jump: