DOS批处理:将系统时钟提前N天?
我需要一些指针来制作 MS-DOS 批处理“函数”,以将系统日历从当前日历提前 N 天。是否有更适合机器的命令,或者我是否坚持使用 DATE
及其一些弗兰肯黑客解析?
I need some pointer crafting an MS-DOS batch "function" to advance the system calendar N number of days from the current one. Is there a more machine-friendly command, or am I stuck with DATE
and some Franken-hack parsing of it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在网上我最喜欢的批处理网站之一 Rob van der Woude 的脚本页面 中,您可以在 示例部分 一个名为 DateAdd.bat。它将根据给定的日期和偏移量计算并打印新的日期。
根据您的需要更改脚本或将其与您自己的脚本一起使用应该相当容易。如果您需要进一步的帮助,请联系我们。
On one of my favorite batch sites on the net Rob van der Woude's Scripting Pages you can find in the examples section a script called DateAdd.bat. It will calculate and print a new date based on a given date and offset.
It should be fairly easy to change the script to your needs or use it along with your own script. Get back to us if you need further help with that.
如果您真正使用的是 MS-DOS,而不是更高级的 cmd.exe,那么您的选择非常有限,因为变量操作非常糟糕。
我确实记得前世需要类似的东西。根据记忆,我们没有试图搞乱日期计算,而是简单地运行一个循环(每天一次迭代),并在循环内将时间设置为 23:59,然后等待五秒左右。不幸的是,我认为早于
ping
所以我们甚至无法使用 睡眠技巧 - 我们必须运行一个冗长的goto
循环才能确定。这样,DOS 自己就能确定“明天”是 9 月 31 日还是 10 月 1 日。
最后,这变得太麻烦了,所以我建议你做我们完成的事情。从 Borland 获取一份 Turbo C 的副本(或者 InPrise 或 Enchilada 或者无论它们现在被称为什么 - 对我来说它们永远) 博物馆网站 并编写一个快速的小 C 程序来为您完成此操作。
If you're truly using
MS-DOS
rather than the more advancedcmd.exe
, your options are very limited since the variable manipulation was pretty bad.I do remember needing something similar in a previous life. From memory, rather than trying to screw around with date calculations, we simply ran a loop (one iteration for each day) and, inside the loop, set the time to 23:59 then wait for five seconds or so. Unfortunately, I think that pre-dated
ping
so we couldn't even use the sleep trick - we had to run a lengthygoto
loop to be certain.That way, DOS itself figured out whether "tomorrow" was the 31st of September or 1st of October.
In the end, it became too much trouble so I would suggest you do what we finished up doing. Grab yourself a copy of Turbo C from Borland's (or InPrise or Enchilada or whatever they're called nowadays - they'll always be Borland to me) museum site and write a quick little C program to do it for you .