Search code examples
iphonetimezbar-sdk

Save the current time when event is performed


In my app i am using zbar sdk to scan ticket and i want to save current time in sqlite when the camera takes the shot . How can i do this. Thanks in advance.


Solution

  • when you click save on ZBarReaderController , this bellow method called..

    - (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
    {
    
    
     NSDate *currentDateandTime = [NSDate date];
       /// and save this date and time in your database
    
      ////with date formate see bellow my edited answer 
      /// this for get string from date with formate
      NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@"EEE, dd-MM-yyyy hh:mm:ss a"];
      NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
      NSLog(dateString); 
    
     /// for get date from string with different formate use bellow code
     NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
     [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"];
    
     NSDate *date = [dateFormatter dateFromString: dateString];
    
    }
    

    also for more detail about NSDate see my blog on bellow link..

    http://parasjoshi3.blogspot.in/2012/01/convertstringtodatedatetostring.html

    i hope this help you...

    :)