JS将指定的时间戳转为UTC时间
Js中获取时间戳可用var dayMiliseconds = parseInt(new Date().valueOf());Js的时间戳单位为毫秒(1s = 1000 ms),下面是一个将制定的格式转化成UTC时间的函数。
//format the date string from webservice to UTC time;
function toUTCtime(dateStr) {
//Date(1381243615503+0530),1381243615503,(1381243615503+0800) dateStr += "";
var utcPrefix = 0;
var offset = 0;
var dateFormatString = "yyyy-MM-dd hh:mm:ss";
var utcTimeString = "";
var totalMiliseconds = 0; var regMatchNums = /\d+/gi;
var regSign = /[\+|\-]/gi;
var arrNums = dateStr.match(regMatchNums);
utcPrefix = parseInt(arrNums[0]);
if (arrNums.length > 1) {
offset = arrNums[1];
offsetHour = offset.substring(0, 2);
offsetMin = offset.substring(2, 4);
offset = parseInt(offsetHour) * 60 * 60 * 1000 + parseInt(offsetMin) * 60 * 1000;
}
if(dateStr.lastIndexOf("+")>-1){
totalMiliseconds= utcPrefix - offset;
} else if (dateStr.lastIndexOf("-") > -1) {
totalMiliseconds = utcPrefix + offset;
} utcTimeString = new Date(totalMiliseconds).format(dateFormatString);
return utcTimeString; }
JS将指定的时间戳转为UTC时间的更多相关文章
- koa2+koa-art-template利用日期管道实现在jat模板中将时间戳转为日期时间
var sp = require("silly-datetime"); var render = require("koa-art-template"); va ...
- js实现UTC时间转为北京时间,时间戳转为时间
用了阿里云的接口,发现其穿的日期是UTC格式的.需要转换. var utc_datetime = "2017-03-31T08:02:06Z"; function utc2beij ...
- UTC时间戳转为时间
/// <summary> /// 将UTC时间转化DateTime时间 /// </summary> /// <returns></returns> ...
- iOS 本地时间 / UTC时间 / 时间戳等操作 / 获取当前年月日
//获得当前时间并且转为字符串 - (NSString *)dateTransformToTimeString { NSDate *currentDate = [NSDate date];//获得当前 ...
- iOS 本地时间、UTC时间、时间戳等操作、获取当前年月日
//获得当前时间并且转为字符串 - (NSString *)dateTransformToTimeString { NSDate *currentDate = [NSDate date];//获得当前 ...
- js 时间戳转为日期格式
原文:js 时间戳转为日期格式 js 时间戳转为日期格式 什么是Unix时间戳(Unix timestamp): Unix时间戳(Unix timestamp),或称Unix时间(Unix time) ...
- js时间戳如何转时间
js时间戳如何转时间 一.总结 一句话总结:Date对象分别获取年now.getFullYear()月now.getMonth()+1日now.getDate()即可 Date对象分别获取年now.g ...
- js将UTC时间转化为当地时区时间
js将UTC时间转化为当地时区时间(UTC转GMT) 我们在进行网站开发的时候有可能会涉及到国外的用户或者用户身在国外,这时就会存在时差问题,比如说我们在中国的时间是08:00,但是此时韩国的时间 ...
- 时间戳转为C#格式时间
经常发现很多地方使用一个时间戳表示时间.比如: 1370838759 表示 2013年6月10日 12:32:39. 我们就需要一个工具,方便地转换这种时间格式 什么是时间戳? 时间戳, 又叫Unix ...
随机推荐
- 无法加载父级样式或设置IIS的asp站点启用父路径
打开IIS 1.单击站点,在"IIS"区域中找到ASP图标,双击. 2.找到"启用父路径"项目,将对应的值设置为"TRUE"即可. 顶
- CentOS 6.8_x64 Oracle 12C 安装
1.下载地址 (需要注册oracle账号) 点击 2.登录CentOS 做准备工作 groupadd oinstall groupadd dba useradd -g oinstall -g dba ...
- couldn't open file: data/coco.names
在ubuntu下配置yolo(v2)的时候,编译了源码后,尝试运行demo: ./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg 结果报错提 ...
- Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)
传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...
- Level Of Management Protocols - SNMP Tutorial
30.2 The Level Of Management Protocols Originally, many wide area networks included management proto ...
- shell的一些应用场景
列出每个IP的连接数 netstat -n | awk '/^tcp/{print $5}' | awk -F: '!/^::/{print $1}' | sort | uniq -c | sort ...
- 深入理解javascript原型和闭包(10)——this
接着上一节讲的话,应该轮到“执行上下文栈”了,但是这里不得不插入一节,把this说一下.因为this很重要,js的面试题如果不出几个与this有关的,那出题者都不合格. 其实,this的取值,分四种情 ...
- Bash 中的 $0 在什么时候不是 argv[0]
每个 C 程序都有一个 main 函数,每个 main 函数都有一个 argv 参数,这个参数是一个字符串数组,这个数组的值是由该 C 程序的父进程在通过 exec* 函数启动它时指定的. 很多人说 ...
- javascript数据结构与算法---检索算法
查找数据有2种方式,顺序查找和二分查找.顺序查找适用于元素随机排列的列表.二分查找适用于元素已排序的列表.二分查找效率更高,但是必须是已经排好序的列表元素集合. 一:顺序查找 顺序查找是从列表的第一个 ...
- HDOJ 4652 Dice
期望DP +数学推导 Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...