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 ...
随机推荐
- C++_基础_类和对象
内容: (1)引用 (2)类型转换 (3)C++社区给C程序员的建议 (4)面向对象编程的概念 (5)类和对象 (6)构造函数 (7)初始化列表及其必要性 1.引用1.1 指针和引用的使用说明(1)指 ...
- HTML与CSS绘制简单DIV布局
HTML代码<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...
- nginx proxy_pass 后面的斜杠
# add / location /app/ { proxy_pass http://$backend/; } # location /app/ { proxy_pass http://$backen ...
- 为IE6-7间接支持:before和:after伪类
:before和:after我们经常会用到,特别是在做移动端页面时,利用它制作文字前后的ICON.图片的垂直居中之类的非常方便且代码简洁(当然,功能远比这些要多的多...). 可是在PC端,由于现在还 ...
- HTML中小问题
1.a标签不添加href这个属性时,不会出现鼠标变成手型~
- Android学习笔记(不定时更新)
<2014-03-20>设置按钮的不同状态 1.res/ layout/ [文件名]myselector.xml 2.把两张不同的按钮图片放到drawable-xxxx文件夹里,mysel ...
- codeforces 245H . Queries for Number of Palindromes 区间dp
题目链接 给一个字符串, q个询问, 每次询问求出[l, r]里有多少个回文串. 区间dp, dp[l][r]表示[l, r]内有多少个回文串. dp[l][r] = dp[l+1][r]+dp[l] ...
- JSWING小工具
项目中需要一个发送指令到指定服务端,取得设备ID及检测数据的小工具,就利用jswing开发了一个简单小组件,最终效果如下: 代码很简单,具体片段如下: Window.java import java. ...
- printf与scanf的返回值、注意点
printf()的返回值为其输出字符串常量的字符数(注意字符数与字数的区别)注意计数针对所有的打印字符,包括空格和不可见的换行字符(不包括字符串的空字符). scanf()函数返回成功读入的项目的个数 ...
- scanf一次给多个变量赋值
本节课程笔记: 一是对多个变量进行赋值,二是对非法输入的值做正确处理(处理方式了解即可,相关函数知识后期讲解),三是美化scanf代码加入输出说明. /* Name:scanf一次给多个变量赋值 Co ...