In IPhone(Objective C) how do I get the current date formatted in miliseconds to send to a server Rest Web Service?

情到浓时终转凉″ 提交于 2020-01-17 03:40:10

问题


I am new to IPhone development. I need to take the current date from device and send to a server in JSon format. The server expects this date to be in milliseconds as since January 1, 1970, 00:00:00 GMT(Unix time) .

I have noticed IPhone has some methods to get the current time in SECONDS, well, should be very easy to transform seconds to milliseconds with a simple * 1000 routine. All the problem begins because as this is my first lines of code with Objective-C for IPhone I am lost trying to get current time in seconds.

How do I get current time in milliseconds in IPhone?

Thanks in advance.


回答1:


double milliseconds = 1000.0 * [[NSDate date] timeIntervalSince1970];



回答2:


CGFloat milliseconds = [NSDate timeIntervalSinceReferenceDate]*1000.0;


来源:https://stackoverflow.com/questions/3990295/in-iphoneobjective-c-how-do-i-get-the-current-date-formatted-in-miliseconds-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!