GMT时间与北京时间的转换
来源:互联网 发布:开通淘宝直通车的条件 编辑:程序博客网 时间:2024/04/28 03:03
文章参考了很多其他技术网站,然后自己再根据需求,调试出来的,感谢其他网站的筒子们,临时关了那些网站,无法附链接了,在此SAY SORRY
js版本的【GMT时间转换成北京时间】代码:
/**************************************************** 功能描述:将GMT时间转换成北京时间 参数说明: value:要格式化的时间 strFormat:格式,如:'Y-m-d H:i:s' ******************************************************/ this.GMTtoTime = function(value){ if(value=="" || value==null){ return ""; } else{ var tempValue = value.replace("T", " "); var dateBefore = tempValue.slice(0,10); var timeBefore = tempValue.slice(11,19); var dateArray = dateBefore.split("-"); var timeArray = timeBefore.split(":"); //注意,Date对象中的getMonth() 返回0~11 var feedDate = Date.UTC(dateArray[0],dateArray[1]-1,dateArray[2],timeArray[0],timeArray[1],timeArray[2],0) + 8*60*60; var now = new Date(); now.setTime(feedDate); if (now.getMonth()<10){ var m=0; m=now.getMonth()+1; var month = "0" + m; }else{ var month = now.getMonth()+1; } if (now.getDate()<10){ var d=0; d=now.getDate()+1; var date = "0" + d; }else{ var date = now.getDate(); } var dateAfter = now.getFullYear() + "-" + month + "-" + date; // var dateAfter = month + "月" + date + "日"; if (now.getHours()<10){ var hour = "0" + now.getHours(); }else{ var hour = now.getHours(); } if (now.getMinutes()<10){ var minute = "0" + now.getMinutes(); }else{ var minute = now.getMinutes(); } var timeAfter = hour + ":" + timeArray[1]+":"+timeArray[2]; var timeFinal = dateAfter + " " + timeAfter; return timeFinal; } }
java版本的【北京时间转成GMT时间】
/** * 将日期转换成GMT日期 方法 * @param d * @return */ public static Date getTimeToGMT(Date d){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); DateFormat gmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); gmt.setTimeZone(TimeZone.getTimeZone("GMT")); String gmtStr=gmt.format(d);//日期 转成 字符串 Date gmt_date =null; try { gmt_date = sdf.parse(gmtStr); //字符串 转成 日期 } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return gmt_date; }
0 0
- GMT时间与北京时间的转换
- iOS时间戳与北京时间的转换
- 从GMT时间转换到当地时间(北京时间)
- Java本地时间与GMT时间的转换
- Java本地时间与GMT时间的转换
- 当前时间与GMT时间转换
- Unix时间戳与正常北京时间转换
- UTC时间与北京时间相互转换
- C++实现北京时间与时间戳转换
- 本地时间(北京时间)和“GMT+8”时区时间的区别?
- UTC时间与北京时间的差多久
- UTC时间与北京时间的差多久
- UTC时间与北京时间的差多久
- UTC时间与北京时间的关系
- UTC时间与北京时间的关系
- UTC时间与北京时间的关系
- GMT 时间转换问题
- GMT时间格式转换
- 【OpenCV】高斯混合背景建模
- 护民图库CAD制图
- logcat 使用总结
- 第四章作业
- HDU1009
- GMT时间与北京时间的转换
- spirng3+hibernate4+blazeds4错误
- C语言中给main函数传递参数!
- Linux分区方案
- Unify:智能手机应用程序开发框架
- C++中const用法总结
- 急聘,需要一名系统架构师-IOS方面的(深圳)
- Android3.1 后广播不响应的问题
- js获取当前<a标签背景色