How to Convert Nsdate into Unix Timestamp iPhone Sdk

How to convert NSDate into unix timestamp iphone sdk?

I believe this is the NSDate's selector you're looking for:

- (NSTimeInterval)timeIntervalSince1970

How to Convert a particular NSDate to UNIX time stamp in ios

time_t unixTime = (time_t) [date timeIntervalSince1970];

was able to solve it by this

How to convert NSDate into Unix timestamp in Objective C/iPhone?

I believe - [NSDate timeIntervalSince1970] is what you want. Jan 1, 1970 is the date of the Unix epoch.

Convert NSDate to Unix Time Stamp for use in Dictionary

I believe that code will work and the error message relates to a different statement.

If you want to put that time_t into a dictionary then you'll need to wrap it in an NSNumber object. However you may as well keep it as an NSTimeInterval (double) and cast it when using it:

NSDate *date = self.datepicker.date;
NSTimeInterval start = [date timeIntervalSince1970]
dict[@"startTime"] = @(start);

However you can also cast it before adding it to the dictionary if you really want to.

How to convert any human readable date to unix timestamp

iOS provides -(NSTimeInterval)timeIntervalSince1970 for NSDate objects which returns the number of seconds since 00:00:00 GMT January 1, 1970. NSTimeInterval is a double floating point type so you get the seconds and fractions of a second.

time_t unixTime = (time_t) [your_date timeIntervalSince1970];

Here time_t is usually a signed 32-bit integer type (long or int).

Creating NSDate from unix timestamp stored in NSNumber on 32/64 bit

It's not a 64-bit issue.

NSTimeInterval is defined as a double so use:

NSNumber *number = @(1388534400.000);
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[number doubleValue]];

How to convert Unix timestamp into Swift NSDate object?

Try this:

var date = NSDate(timeIntervalSince1970: timeInterval)

Converting a unix timestamp to NSdate using local timezone

This should do what you need with current locale

double unixTimeStamp =1304245000;
NSTimeInterval _interval=unixTimeStamp;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
NSDateFormatter *formatter= [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateFormat:@"dd.MM.yyyy"];
NSString *dateString = [formatter stringFromDate:date];


Related Topics



Leave a reply



Submit