NSDate conversion utilities
// Gets UTC NSDate from DateTime(.Net/WCF).
+ (NSDate *)fromDateTime:(NSString *)dateTime {
NSDate *utcDate;
if ([dateTime isMemberOfClass:[NSNull class]]) {
utcDate = nil;
} else {
NSInteger offset = [[NSTimeZone timeZoneWithName:@"UTC"] secondsFromGMT];
utcDate = [[NSDate dateWithTimeIntervalSince1970:[[dateTime substringWithRange:NSMakeRange(6, 10)] intValue]] dateByAddingTimeInterval:offset];
}
return utcDate;
}
// Converts NSDate to UTC DateTime(.Net/WCF).
- (NSString *)toDateTime {
NSDateFormatter *utcFormatter = [[NSDateFormatter alloc] init];
[utcFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
return [NSString stringWithFormat:@"/Date(%.0f000%@)/", [self timeIntervalSince1970],[utcFormatter stringFromDate:self]];
}
// Converts UTC NSDate to local time.
- (NSString *)utcToLocalTime {
// offset second
NSInteger seconds = [[NSTimeZone systemTimeZone] secondsFromGMT];
NSDateFormatter *localTimeFormatter = [[NSDateFormatter alloc] init];
[localTimeFormatter setDateFormat:@"MM/dd/yyyy HH:mm"];
[localTimeFormatter setTimeZone :[NSTimeZone timeZoneForSecondsFromGMT: seconds]];
return [localTimeFormatter stringFromDate:self];
}
NSDate conversion utilities的更多相关文章
- NiosII常用函数整理
NiosII常用函数整理 IO操作函数函数原型:IORD(BASE, REGNUM) 输入参数:BASE为寄存器的基地址,REGNUM为寄存器的偏移量函数说明:从基地址为BASE的设备中读取寄存器中偏 ...
- Computer Graphics Research Software
Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...
- Awesome Go
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Go 语言相关的优秀框架,库及软件列表
If you see a package or project here that is no longer maintained or is not a good fit, please submi ...
- Awesome Go (http://awesome-go.com/)
A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...
- Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software
Awesome Go financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...
- Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...
- iOS NSDate等时间类的使用
一.NSDate NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是NSDate的私有子类的实体. NSDate存储的是GMT时间,使用的时候会根据 ...
- View and Data API Tips : Conversion between DbId and node
By Daniel Du In View and Data client side API, The assets in the Autodesk Viewer have an object tree ...
随机推荐
- linux使用wget纯命令下载JDK的方法(凑字数)
linux使用wget纯命令下载JDK的方法 linux使用wget纯命令下载JDK的方法 Oracle官网上下载jdk,需要点击accept licence的才能下载,所以一般的直接使用wget下载 ...
- html回车事件
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- Decorators and Wrappers in Python
python代码一贯以优雅,简洁著称,而有时侯反而会让人难以理解,比如说wrapper(或者说decorator),这种方式提高了代码的可重用性,使用起来更简洁方便. 举个例子,比如WebApp常用的 ...
- qt5集成libcurl实现tftp和ftp的方法一:搭建环境(五篇文章)
最近使用QT5做一个软件,要求实现tftp和ftp文件传输,使用QT5开发好UI界面等功能,突然发现QT5不直接提供tftp和ftp支持,无奈之下只好找第三方库来间接实现,根据网友的介绍,libcur ...
- 我的 Azure VM 为何会重新启动?
在客户创建的客服案件中, Azure VM意外重启是一个常见的问题,客户要求客服确定重新启动的原因.希望下面的详细说明能够帮助您了解 Azure VM重新启动的原因. WindowsAzure大约 ...
- aliyun opts 集锦
<一,>,aliyun 使用数据盘(aliyun新增数据盘使用,创建vg,aliyun 镜像系统本身未使用lvm-vg-lv) 1.1直接挂载文件系统 较易,不做分析 http://hel ...
- UVA - 1103Ancient Messages(dfs)
UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study te ...
- Hive索引
1. Hive索引概述 Hive的索引目的是提高Hive表指定列的查询速度. 没有索引时.类似'WHERE tab1.col1 = 10' 的查询.Hive会载入整张表或分区.然后处理全 ...
- 详解Objective-C中委托和协议
Objective-C委托和协议本没有任何关系,协议如前所述,就是起到C++中纯虚类的作用,对于“委托”则和协议没有关系,只是我们经常利用协议还实现委托的机制,其实不用协议也完全可以实现委托. AD: ...
- nbtstat 查询IP地址对应的计算机名称
使用命令nbtstat -a ipaddress即可,例如:nbtstat -a 192.168.1.2.