現在の日付と時刻を秒単位の数値にする方法を見つけようとしていますか?
この投稿を見ましたiPhoneの日付文字列でミリ秒単位で使用するフォーマット文字列は何ですか?しかし、私は実際にそれをただの数にしようとしています...
編集:申し訳ありませんが秒を意味しました
UTC
タイムスタンプが必要int
で、32ビットよりも格納したい場合は、代わりlong long
に使用できません。範囲が広く、整数として使用できます。
NSString *dateValue = @"2011-06-23T13:13:00.000";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSString *formatString = @"yyyy-MM-dd'T'HH:mm:ss.SSS";
[formatter setDateFormat:formatString];
NSDate *date = [formatter dateFromString:dateValue];
long long dateInMillis = [date timeIntervalSince1970]*1000; //This will give milliseconds
long dateInSeconds = [date timeIntervalSince1970]; //This will give seconds
編集:現在の日付のlong
値の使用
//This will give seconds of current date
long dateInSeconds = [[NSDate date] timeIntervalSince1970];
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加