-1

It is too much confusing and i have pasted my code below.

I have a eopoc time.

// Function that converts eopc to NSString

NSString * ConvertEpocToDateStr(NSString *epoc)
{

    NSString *res;

    NSTimeInterval sec = [epoc doubleValue]/1000.0;

    NSDate *eDate = [[NSDate alloc] initWithTimeIntervalSince1970:sec];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];


    [dateFormatter setDateFormat:@"MM/dd hh:mm a"];
    dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];
    NSLog (@" Time in your Zone is %@ ", [[dateFormatter timeZone] description]);
    res = [dateFormatter stringFromDate:eDate];

    return res;
}

// From NSString to back NSDate.

NSDate * backToDate (NSString * dInStr )
{
    NSDateFormatter *dFormatter = [[NSDateFormatter alloc] init];
    [dFormatter setDateFormat:@"MM/dd hh:mm a"];
    dFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];

    NSDate *FromString = [dFormatter dateFromString:dInStr];
    return dFromString;

}

And, I tried to print below .

epoc -> 1397600251077

ConvertEpocToDateStr -> 04/16 03:47 am backToDate -> 2000-04-15 22:17:00 +0000

Both should be same right? I am not sure where/what i am missing?

Whoami
  • 13,930
  • 19
  • 84
  • 140

1 Answers1

1

Of course, you get the same dates. IST is 5.30 h ahead of GMT+0. Since you drop out year in your direct formatter and use the date time string without the year by default it is set to 2000.

Evidently, 2000-04-15 22:17:00 +0000 is the same as 2000-04-16 03:47:00 +0530.

malex
  • 9,874
  • 3
  • 56
  • 77