时间戳转换为时间

根据时间戳转换为具体的具体的时间信息,需要注意的是根据要根据具体时区做出调整

实现代码如下:

NSString *[email protected]"1368082020";//时间戳

NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec

NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];

NSLog(@"date:%@",[detaildate description]);

//实例化一个NSDateFormatter对象

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

//设定时间格式,这里可以设置成自己需要的格式

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];

时间: 2024-08-25 08:33:24

时间戳转换为时间的相关文章

SQLServer中将时间戳转换为时间格式

--在sql中将时间戳转换为时间类型 SQL里面有个DATEADD的函数.时间戳就是一个从1970-01-01 08:00:00到时间的相隔的秒数.所以只要把这个时间戳加上1970-01-01 08:00:00这个时间就可以得到你想要的时间了select DATEADD(second,1268738429 + 8 * 60 * 60,'1970-01-01 00:00:00') 注解:北京时间与GMT时间关系    1.GMT是中央时区,北京在东8区,相差8个小时 2.所以北京时间 = GMT时

C# Unix时间戳转换为时间

在做一些接口的时候,比如返回数据中有一个时间的属性,它的值是使用Unix时间戳表示的,当我们处理它(保存到本地或者格式化前台展示)时需要转换成日期时间,在此就需要根据时间戳转换为日期时间 (注:Unix时间戳是当前标准时区时间与1970年1月1日所经历的总秒数) /// <summary> /// 根据时间戳转换为当前时间 /// </summary> /// <param name="timeSpan">时间戳(精确到秒)</param>

微信小程序如何把后台返回的多条json数据的时间戳转换为时间放到页面上 (微信小程序 时间戳转换为时间)

小程序端 在utils文件夹下的util.js写入 //时间戳转换时间   function toDate(number){   var n=number * 1000;   var date = new Date(n);   var Y = date.getFullYear() + '/';   var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/';   var D = date

C# 时间戳转换为时间格式

// 时间戳转为格式 public DateTime StampToDateTime(string timeStamp) { DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(lTime); return

js实现的时间戳和时间日期的转换

js实现的时间戳和时间日期的转换:时间戳和时间日期的转换是常见的操作,下面就通过代码实例介绍一下如何实现它们之间的相互转换.建议事先参阅javascript中Date()构造函数参数介绍一章节.一.时间日期转换为时间戳:现在有这么一个时间日期:"2013/5/12 20:10:20",下面将其转换为时间戳形式:代码如下: var dateStr="2013/5/12 20:10:20"; var date=new Date(dateStr); console.log

如何用JS/HTML将时间戳转换为“xx天前”的形式【附源码,转

如果我们有一份过去时间戳,如何使用JS/HTML将时间戳转换为"xx天前"的形式呢,以下是完整代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script src="https://ajax.googleapis.com/aja

SQL时间戳日期时间转换

将时间戳转换为日期格式:比如降1455504268→2016-02-15 10:44:28 1 select device.register_time a,FROM_UNIXTIME(device.register_time,'%Y-%m-%d %H:%i:%s') as registerTime from tm_data_newdevice device MySQL的DATE_ADD() 函数向日期添加指定的时间间隔. 语法: DATE_ADD(date,INTERVAL expr type)

js_时间戳和时间格式之间的转换。

关于我的理解,简单明了点: 时间戳:把一个日期使用一个数字表示出来,这个数字就是这个日期的秒数. 日期:就是我们常见的时间表现形式. 时间戳对于一般看时间不够直观明了,可是在程序的世界里作用可大了. 获取当前的时间戳: 1 // 获取当前时间戳(以s为单位) 2 var timestamp = Date.parse(new Date()); 3 timestamp = timestamp / 1000; 获取某一日期的时间戳: 1 // 获取某个时间格式的时间戳 2 var stringTime

postgresql数据库的 to_date 和 to_timestamp 将 字符串转换为时间格式

数据库中:字符串 转换为 时间格式 二者区别: to_data 转换为 普通的时间格式        to_timestamp 转换可为 时间戳格式出错场景: 比较同一天 日期大小的时候,很容易出错 例如:        select current_timestamp from pub_employee        结果如下:            select current_timestamp <= to_date('2018-03-12 18:47:35','yyyy-MM-dd hh