// 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. Android 内部存储安装apk文件实现

    目前国内市场的山寨机横行,安卓手机升级也是一天一个样,对于原来老手机可能没有SDCARD,导致我们的APP不能下载资源,无法更新APP,针对这种情况有以下解决方案.通过以下函数判断是否有SD卡再判断下 ...

  2. ngrok原理浅析(转载)

    之前在进行 微信Demo开发时曾用到过 ngrok这个强大的tunnel(隧道)工具,ngrok在其github官方页面上的自我诠释是 "introspected tunnels to lo ...

  3. Python的maketrans() 方法

    描述 Python maketrans() 方法用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标. 注:两个字符 ...

  4. Data Mining

    数据探索: 数据探索有助于选择合适的数据处理与数据分析技术.它甚至可以解决一些数据挖掘问题. 1.汇总统计:量化用单个数或数据的集合展示数据的特性: 如集合的平均值.方差. 2.可视化技术:以图形或表 ...

  5. spring 资源加载使用说明

    Spring 提供了一个强大加载资源的机制,不但能够通过“classpath:”.“file:” 等资源地址前缀识别不同的资源类型,还支持Ant 风格带通配符的资源地址. 首先,我们来了解一下Spri ...

  6. swig模板 html代码自然状态下输出是转义的,必须加一个函数来转换为html代码;

    <div>{{o.content|raw}}</div> |raw 相当于一个函数,转义函数,最终输出结果为html代码:

  7. linux杂谈(十七):iscsi存储分离技术

    1.iscsi简单介绍 ​ ​iSCSI利用了TCP/IP的port 860 和 3260 作为沟通的渠道.透过两部计算机之间利用iSCSI的协议来交换SCSI命令,让计算机能够透过快速的局域网集线来 ...

  8. raphael入门到精通---入门篇之总览

    什么是Raphael raphael.js是一小巧的javascript库,它可以在web上画矢量图简化你的工作,如果你想创建你指定的图表,图形区域或者可移动的组件,那么就使用raphael吧 话不多 ...

  9. HTML静态网页(标签、表格)

    HTML静态网页: 打开DREAMWEAVER,新建HTML,如下图: body的属性: bgcolor 页面背景色 background  背景壁纸.图片 text  文字颜色 topmargin ...

  10. mac的svn之cornerstone简易教程

    链接地址:http://jingyan.baidu.com/article/9989c74612a55af648ecfef2.html 背景: 关于cornerstone的介绍很少: 这里介绍mac的 ...