NSDate Min and Max Possible Values

前端 未结 3 1852
执念已碎
执念已碎 2021-01-07 19:07

Anyone know what the minimum and maximum possible values are for an NSDate?

3条回答
  •  走了就别回头了
    2021-01-07 19:38

    maximum should be: 5828963-12-20 00:00:00 +0000 because

    NSDate *dateSinceNow = [NSDate dateWithTimeIntervalSinceNow:DBL_MAX];
    NSDate *dateSindeReferenceDate = [NSDate dateWithTimeIntervalSinceReferenceDate:DBL_MAX];
    NSLog(@"min: %@, max: %@", dateSinceNow, dateSindeReferenceDate);
    

    is the same.

    minimum i get this is: 0001-01-01 00:00:00 +0000

    cause this is what i get when i try:

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
    [df setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    NSDate *myDate = [df dateFromString: @"0001-01-01 00:00:00"];
    NSLog(@"%@", myDate);
    

    but this is current era as pointed out by davedelong

    so if you try the first example with - DBL_MAX you get: 41221-07--2147483641 00:00:00 +0000. no idea what era this is...

提交回复
热议问题