开发者

Pass Unix Timestamp to REST API Using Curl Under Windows

I am using curl to interact with the REST API of JetBrains' YouTrack issue tracker from the Windows command line. It is a very simple process that uses no other utility than curl (built as a single windows executable). I'd like to keep the simplicity, but I have run into an issue. One of the API's wants me to pass a Unix timestamp, but there is no Windows utility to generate one. I suppose it would be simple enough to write a utility myself, but I'd prefer not to reinvent the wheel.

The API I am calling is here:

http://confluence.jetbrains.net/display/YTD3/PUT+Version

And I am looking to populate the "releaseDate" field.

Is there a utility to generate the Unix timestamp on windows that is self contained, ie I don't need to install cygwin or something huge like that.

EDIT: For the record here is what I ended up doing (its part of a *.bat file):

type nul >pcmd.ps1
echo $timestamp=Get-Date -UFormat '%%s' >>pcmd.ps1
echo $timestamp=[Math]::Truncate($timestamp) >> pcmd.ps1
echo curl "http://myserver/rest/admin?releaseDate=$timestamp&isReleased开发者_如何学JAVA=true" -v -b yt --upload-file empty >>pcmd.ps1

type pcmd.ps1

powershell - <pcmd.ps1


with native MS powershell this may work:

Get-Date -UFormat "%s" 

http://technet.microsoft.com/en-us/library/dd347647.aspx


DateTime.Now.Ticks in Windows is the number of "hundreds of nano seconds" since 01/01/0001.

Unix timestamp is the number of seconds since 01/01/1970.

You should be able to subtract to get the target timestamp.

DateTime dateTimeIWant = new DateTime(2011,05,01);
int targetUnixTimeStamp = (dateTimeIWant.Ticks - new DateTime(1970,1,1).Ticks) / 10000;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜