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
How to Add Line Break for Uilabel
How to Make View the Size of Another View in Swiftui
How to Switch to Different Storyboard for iPhone 5
Uitableviewcell Checkmark to Be Toggled on and Off When Tapped
Screenshot for Avplayer and Video
Module Compiled with Swift 4.2.1 Cannot Be Imported by the Swift 5.0 Compiler
Write Extend File Attributes Swift Example
iOS Open Youtube App with Query (Url Schemes)
Color All Occurrences of String in Swift
How to Use a Custom Font with Dynamic Text Sizes in iOS7
Native Facebook App Does Not Open with Facebook Login in iOS 9
Warning: the Copy Bundle Resources Build Phase Contains This Target's Info.Plist File
Mkmapview Mkpointannotation Tap Event
Disabling Automatic Scrolling of Uitableview When Editing Uitextfield Inside Uitableviewcell