converting timestamp to nsdate format

后端 未结 4 756
一个人的身影
一个人的身影 2020-12-08 13:21

I want to convert my timestamp value 1308031456 to NSDate format (which yields the value Tue, 14 Jun 2011 06:04:16 GMT in online web c

相关标签:
4条回答
  • 2020-12-08 13:58

    You can use the use the method dateWithTimeIntervalSince1970: to convert the timestamp you've which is the epoch time.

    NSDate * myDate = [NSDate dateWithTimeIntervalSince1970:1308031456];
    
    0 讨论(0)
  • 2020-12-08 14:03

    OBJ - C: Use dateWithTimeIntervalSince1970:,

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    

    SWIFT: Use init(timeIntervalSince1970:)

    let date = NSDate(timeIntervalSince1970:timeStamp)
    
    0 讨论(0)
  • 2020-12-08 14:09

    See the various example on date formatting and getting date from timestamp from apple

    Use Formatter Styles to Present Dates and Times With the User’s Preferences

    Convert TimeStamp to NSDate in Objective-C

    0 讨论(0)
  • 2020-12-08 14:23

    In obj c

    double timeStamp = 1513330403393;
    NSTimeInterval unixTimeStamp = timeStamp / 1000.0;
    NSDate *exactDate = [NSDate dateWithTimeIntervalSince1970:unixTimeStamp];
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"dd/MM/yyy hh:mm a";
    NSString  *finalate = [dateFormatter stringFromDate:exactDate];
    

    In Swift

    let timeStamp = 1513330403393
    let unixTimeStamp: Double = Double(timeStamp) / 1000.0
    let exactDate = NSDate.init(timeIntervalSince1970: unixTimeStamp)
    let dateFormatt = DateFormatter();
    dateFormatt.dateFormat = "dd/MM/yyy hh:mm a"
    print(dateFormatt.string(from: exactDate as Date))
    
    0 讨论(0)
提交回复
热议问题