私のアプリでは、zbar sdkを使用してチケットをスキャンしており、カメラがショットを撮るときにsqliteで現在の時間を節約したいと考えています。これどうやってするの。前もって感謝します。
3 に答える
1
あなたはこのようなものを書くことができます:
NSDate *currentTime = [NSDate date];
NSDateComponents
次に、必要に応じて、またはを使用してNSDateオブジェクトから適切な値を抽出できNSDateFormatter
ます。
于 2012-10-04T05:19:58.873 に答える
1
次のコードを使用して、デバイスのローカル現在時刻を取得します。
NSDate* sourceDate = [NSDate date];
NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];
これがコーディングに大いに役立ちますように
于 2012-10-04T05:17:34.793 に答える
0
ZBarReaderController で保存をクリックすると、この次のメソッドが呼び出されます..
- (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];
}
また、NSDate の詳細については、以下のリンクにある私のブログを参照してください。
http://parasjoshi3.blogspot.in/2012/01/convertstringtodatedatetostring.html
これがお役に立てば幸いです...
:)
于 2012-10-04T05:31:11.090 に答える