4 Answers

  1. Jim- Reply

    2019-11-15

    Following code for getting date and time into Millisecond.

    NSTimeInterval timeInMiliseconds = [[NSDate date] timeIntervalSince1970];
    

    For more detail refer apple documentation.

    ----Edited----

    NSString *dateString = @"21-04-2015 14:23";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm"];
    NSDate *dateFromString = [[NSDate alloc] init];
    dateFromString = [dateFormatter dateFromString:dateString];
    NSTimeInterval timeInMiliseconds = [dateFromString timeIntervalSince1970]*1000;
    
  2. Jimmy- Reply

    2019-11-15

    For that you need to multiply time gap by 1000, as time interval is in seconds and as float value. so simply multiply by 1000. For simple example I add selector

     NSDate *lastOneminute = [NSDate date];
    [self performSelector:@selector(timeInterval:) withObject:lastOneminute afterDelay:60.0];
    

    and after 60 seconds selector call is :

     - (void)timeInterval:(id)timeGap
    {
        NSLog(@"time interval : %@",timeGap);
    
        NSTimeInterval timeInMiliseconds = [[NSDate date] timeIntervalSinceDate:timeGap] * 1000;
        NSLog(@"milisecond : %f",timeInMiliseconds);
    }
    
  3. Joe- Reply

    2019-11-15

    double timestamp = [[NSDate date] timeIntervalSince1970];
    int64_t timeInMilisInt64 = (int64_t)(timestamp*1000);
    
    #pragma mark - Date
    
    
       -(void)DateCalc
        {
    
    
            NSDate *today = [NSDate date];
            NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setDateFormat:@"dd/MM/yyyy"];
            dateString = [dateFormat stringFromDate:today];
    
    
            NSCalendar *calendar = [NSCalendar currentCalendar];
            NSDateComponents *comps = [NSDateComponents new];
            comps.day = 7;
            NSDate *sevenDays = [calendar dateByAddingComponents:comps toDate:[NSDate date] options:0];
            [dateFormat setDateFormat:@"dd/MM/yyyy"];
            EndingDate = [dateFormat stringFromDate:sevenDays];
    
    
        }
    
  4. John- Reply

    2019-11-15

    You can use below code

        NSString *dateStr = @"21-04-2015 14:23";
    
        // Convert string to date object
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"dd-MM-YYYY HH:mm"];
        NSDate *date = [dateFormat dateFromString:dateStr];
    
        ////2014-12-21 08:53:00 +0000 date
        //// 1419151980000 -- milli seconds    
        NSTimeInterval timeInMiliseconds = [date timeIntervalSince1970]*1000;
    

    Hope it helps you...!

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>