开发者

Get Current Date Time in FileTime structure in Objective-C

开发者 https://www.devze.com 2023-04-04 16:00 出处:网络
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:

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号