// 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的更多相关文章

  1. NiosII常用函数整理

    NiosII常用函数整理 IO操作函数函数原型:IORD(BASE, REGNUM) 输入参数:BASE为寄存器的基地址,REGNUM为寄存器的偏移量函数说明:从基地址为BASE的设备中读取寄存器中偏 ...

  2. Computer Graphics Research Software

    Computer Graphics Research Software Helping you avoid re-inventing the wheel since 2009! Last update ...

  3. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  4. Go 语言相关的优秀框架,库及软件列表

    If you see a package or project here that is no longer maintained or is not a good fit, please submi ...

  5. Awesome Go (http://awesome-go.com/)

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  6. 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 ...

  7. 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 ... 这个错误是因为有两个相 ...

  8. iOS NSDate等时间类的使用

    一.NSDate NSDate对象用来表示一个具体的时间点. NSDate是一个类簇,我们所使用的NSDate对象,都是NSDate的私有子类的实体. NSDate存储的是GMT时间,使用的时候会根据 ...

  9. 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 ...

随机推荐

  1. Convert Sorted List to Balanced Binary Search Tree (BST)

    (http://leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html) Given a singly linked list ...

  2. USACO Section 5.1 Fencing the Cows(凸包)

    裸的凸包..很好写,废话不说,直接贴代码. ----------------------------------------------------------------------------- ...

  3. tengine install

    ./configure --prefix=/home/admin/local/tengine --with-http_stub_status_module --with-http_ssl_module ...

  4. C++小知识之Map用法

    Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作! 1. map最基本的构造函数:    map<st ...

  5. 《JavaScript+DOM编程艺术》的摘要(五)-----添加insertAfter

    在JS原生里面,没有提供insertAfter这个方法,不过我们可以利用appendChild.insertBefore.parentNode这些方法创建一个insertAfter方法,代码如下: f ...

  6. MVC进阶之路:依赖注入(Di)和Ninject

    MVC进阶之路:依赖注入(Di)和Ninject 0X1 什么是依赖注入 依赖注入(Dependency Injection),是这样一个过程:某客户类只依赖于服务类的一个接口,而不依赖于具体服务类, ...

  7. Protel99se教程一:建立一个数据库文件

    学习Protel99 SE的第一步,是建立一个DDB文件,也就是说,使用protel99se进行电路图和PCB设计,以及其它的数据,都存放在一个统一的DDB数据库中的 一.打开protel 99se后 ...

  8. mysql null值问题

    mysql> create table test( sn int, -> `createdTime` datetime NOT NULL COMMENT '创建时间', -> `up ...

  9. Java Native Interface Specification(JNI)

    Java Native Interface Specification(JNI) 使用场景: 需要的功能,标准的java不能提供 有了一个用其他的语言写好的工具包,希望用java去访问它 当需要高性能 ...

  10. poj 1815 Friendship (最小割+拆点+枚举)

    题意: 就在一个给定的无向图中至少应该去掉几个顶点才干使得s和t不联通. 算法: 假设s和t直接相连输出no answer. 把每一个点拆成两个点v和v'',这两个点之间连一条权值为1的边(残余容量) ...