我找到了这个程序http://baiyunmanor.com/blog/work/get-current-date-time-in-dos-batch-file/
但我不知道该怎么回事
:: datetime.bat
Run Code Online (Sandbox Code Playgroud)
到底意味着什么?
acd*_*ior 59
::(也称为评论标签)是一个评论REM.
它们之间存在一些差异.主要是:
REM一个::线显示,但不符合评论ECHO ONREM可以执行行尾插入符号(即,::以行开头的行的末尾::使下一行也是注释).^具有特殊的逻辑,可能会导致括号内的问题 - 在内部使用时要小心:: ::.Aac*_*ini 59
以双冒号开头的行表示命令处理器忽略的无效标签,因此可用于插入注释.由于无法跟踪的原因,许多人使用::在批处理文件中插入注释,但您必须意识到其使用中存在一些陷阱,这些陷阱在Koterpillar的答案中给出的链接中有所描述.似乎第一次使用::而不是REM命令的目的是加速在慢速机器(即:软盘)中执行批处理文件,但这个原因并不是多年前使用双冒号的有效理由.
任何包含无效标签的行都将被命令处理器忽略,您几乎可以使用任何特殊字符来生成无效标签.例如:
@echo off
:~ This is a comment
:` This is a comment
:! This is a comment
:@ This is a comment
:# This is a comment
:$ This is a comment
:% This is a comment
:^ This is a comment
:& This is a comment
:* This is a comment
:( This is a comment
:) This is a comment
:_ This is a comment
:- This is a comment
:+ This is a comment
:= This is a comment
:{ This is a comment
:} This is a comment
:[ This is a comment
:] This is a comment
:| This is a comment
:\ This is a comment
:: This is a comment
:; This is a comment
:" This is a comment
:' This is a comment
:< This is a comment
:> This is a comment
:, This is a comment
:. This is a comment
:? This is a comment
:/ This is a comment
echo OK
Run Code Online (Sandbox Code Playgroud)
换句话说:如果你想插入注释而你不想使用REM命令(虽然我想不出任何理由这样做),你有32个可能的字符组合来做到这一点.为什么你应该使用这个:::?仅仅因为35年前编写的一些旧程序呢?
Kot*_*lar 18
以冒号开头的行是一个标签,您可以跳转到goto:
goto end
:end
Run Code Online (Sandbox Code Playgroud)
以双冒号开头的行是一个标签,除非您不能,甚至意外地跳转到它:
goto :end REM this doesn't work
::end
Run Code Online (Sandbox Code Playgroud)
因此,双冒号用于评论行.
资料来源:http://www.robvanderwoude.com/comments.php
如acdcjunior Labels所述,它::具有特殊的逻辑,可能会导致括号内的问题
这里有几个样本
样品1
IF 1==1 (
::
)
Run Code Online (Sandbox Code Playgroud)
样品1的输出
) was unexpected at this time.
Run Code Online (Sandbox Code Playgroud)
样本2
IF 1==1 (
::
::
)
Run Code Online (Sandbox Code Playgroud)
样本2的输出
The system cannot find the drive specified.
Run Code Online (Sandbox Code Playgroud)