Get Current Date Time in FileTime structure in Objective-C
I am trying to get current Date Time in FileTime structure in objective-c, is th开发者_如何学JAVAat possible? Thanks.
I found an elegant solution for this:
/**
* number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
*/
#include <sys/time.h>
#define EPOCH_DIFF 11644473600LL
unsigned long long getfiletime()
{
struct timeval tv;
unsigned long long result = EPOCH_DIFF;
gettimeofday(&tv,NULL);
result += tv.tv_sec;
result *= 10000000LL;
result += tv.tv_usec * 10;
return result;
}
store the current time in FileTime using:
NSString* timeStamp = [NSString stringWithFormat:@"%llu",getfiletime()];
Do you mean "YYYY:MM:DD:HH:MM:SS"
You can use the following code.
NSDateFormatter *formatDate = [[NSDateFormatter alloc] init];
[formatDate setDateFormat:@"yyyy:MM:dd:HH:mm:ss"];
NSDate *now = [[NSDate alloc] init];
NSString *formattedDate = [formatDate stringFromDate:now];
NSLog(@"%@", formattedDate);
[now release];
[formatDate release];
精彩评论