// 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. IISExpress实现外部访问

    首先修改IISExpress配置文件 \IISExpress\config\applicationhost.config 在website中添加一个binding <binding protoc ...

  2. symfony2-不同bundle的entity的一对多关系

    重点:其实和普通一个bundle中一样,只是把entity地址写全就行. 例子: 表commentone (多方) 表shopone(一方) 在Userbundle中的Commentone实体对应关系

  3. CSS background-repeat 属性

    ###起因 >今天遇到一个问题,就是在给一个元素设置width 属性为100% 之后, 鼠标放上去之后,仍然只有部分是阴影状态,如下图所示: --- 经过一番思索,这TM 不就是,hover 上 ...

  4. 【LeetCode题意分析&解答】37. Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  5. (Problem 39)Integer right triangles

    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exact ...

  6. Delphi的WebBrowser改造,对网页中Alter等对话框的改造方法(通过COM来改造)

    刚有一段时间没做博客了,今天刚好有人问了这个问题,而自己以前也弄过,于是这里有了一篇新的博文. 关于改造WebBrowser控件的一些技巧,大家可以参考MSDN或者蒋晟写的一个东西,里面有讲的很详细的 ...

  7. Windows Azure 自动伸缩已内置

     WindowsAzure平台提供的主要优点之一是能够在有需要时快速缩放云中的应用程序以响应波动.去年7月以前,您必须编写自定义脚本或使用其他工具(如Wasabi或MetricsHub)来启用自动 ...

  8. Java内存模型-jsr133规范介绍

    原文地址:http://www.cnblogs.com/aigongsi/archive/2012/04/26/2470296.html; 近期在看<深入理解Java虚拟机:JVM高级特性与最佳 ...

  9. android播放html5视频,仅仅有声音没有图像视频

    在AndroidManifest.xm中l增加 <activity .... android:hardwareAccelerated="true" />

  10. python闭包以及装饰器

    通俗的定义:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure).它只不过是个“内层”的函数,由一个名字(变量)来指代,而这个名字(变 ...