views:

21

answers:

2

Hi,

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.

A: 
CGFloat milliseconds = [NSDate timeIntervalSinceReferenceDate]*1000.0;
Mo
Hi, I have just tested this routine. I am a bit confused about how to correctly transform this number in a string without changing it and than I will send to server to test it. Can u help me? How to I print this exactly number (milliseconds) in a String format to send to server?
Marcos Maia
+1  A: 
double milliseconds = 1000.0 * [[NSDate date] timeIntervalSince1970];
aBitObvious
I have tryied this routine and this is returning a negative number when I try to print it using a double mask. NSLog(@"Value is = %d", milliseconds);
Marcos Maia
Use %f for doubles, not %d. See [String Format Specifiers](http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/Strings/Articles/formatSpecifiers.html%23//apple_ref/doc/uid/TP40004265).
aBitObvious
Hi, I have just used %f as you suggested and it worked perfectly. Thank you.
Marcos Maia