问题描述
我按如下方式检索 NSTimeInterval:
I retrieve the NSTimeInterval as follows:
NSTimeInterval milisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000);
记录此内容:UNIX 时间戳:1307710190993.865967"
Which logs this:UNIX Timestamp: "1307710190993.865967"
我只希望点之前的值像这样用 JSON 发送:
I only want the value before the dot to send with JSON like this:
"/日期(1307710131826+0200)/"
有什么建议吗?
提前致谢,
推荐答案
获取自 1970 年 UNIX Timestamp 以来以毫秒为单位的当前时间戳.
Get the current timestamp in milliseconds since 1970 UNIX Timestamp.
NSTimeInterval millisecondedDate = ([[NSDate date] timeIntervalSince1970] * 1000);
将milliesecondedDate 格式化为没有小数的字符串.
Format the milliesecondedDate to a string with no decimals.
NSString* formattedMilliseconds = [NSString stringWithFormat:@"%.0f", millisecondedDate];
以 DateTime .net 格式设置时间戳.
Set up the timestamp in DateTime .net format.
NSString *startOfDateFormat = @"/Date(";
NSString *endOfDateFormat = @"+0200)/";
NSString *dateTimeNow = [NSString stringWithFormat:@"%@%@%@",startOfDateFormat, formattedMilliseconds, endOfDateFormat];
这样做可能有更好的解决方案,但目前这对我有用.
There is probably a much better solution for doing this, but this worked for me for now.
这篇关于POST 的 NSTimeInterval 格式,JSON 目标 c 到 DateTime .net 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!