Batch: Timestamp to UNIX Time

前端 未结 5 742
感情败类
感情败类 2020-12-16 16:44

For all I know, Batch does not have a command that gives the UNIX time. The closest one I can find is %time%, which only displays the timestamp.

Is ther

5条回答
  •  臣服心动
    2020-12-16 17:36

    What about simple 1-line long C program returning UNIX timestamp? You can retrieve value from %errorlevel% in batch script.

    #include 
    #include 
    
    int main(void)
    {
        return (int) time(NULL);
    }
    

    In my test in command prompt it worked:

    C:\Users\dabaran\Desktop\cs50\src\C>.\time || echo %errorlevel% && set mytstamp=%errorlevel%
    1419609373
    
    C:\Users\dabaran\Desktop\cs50\src\C>echo %mytstamp%
    1419609373
    

提交回复
热议问题