<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
// 获取当前时间戳(以s为单位)
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
//当前时间戳为:1403149534
console.log("当前时间戳为:" + timestamp);// 获取某个时间格式的时间戳
var stringTime = "2014-07-10 10:21:12";
var timestamp2 = Date.parse(new Date(stringTime));
timestamp2 = timestamp2 / 1000;
//2014-07-10 10:21:12的时间戳为:1404958872
console.log(stringTime + "的时间戳为:" + timestamp2);// 将当前时间换成时间格式字符串
var timestamp3 = 1403058804;
var newDate = new Date();
newDate.setTime(timestamp3 * 1000);
// Wed Jun 18 2014
console.log(newDate.toDateString());
// Wed, 18 Jun 2014 02:33:24 GMT
console.log(newDate.toGMTString());
// 2014-06-18T02:33:24.000Z
console.log(newDate.toISOString());
// 2014-06-18T02:33:24.000Z
console.log(newDate.toJSON());
// 2014年6月18日
console.log(newDate.toLocaleDateString());
// 2014年6月18日 上午10:33:24
console.log(newDate.toLocaleString());
// 上午10:33:24
console.log(newDate.toLocaleTimeString());
// Wed Jun 18 2014 10:33:24 GMT+0800 (中国标准时间)
console.log(newDate.toString());
// 10:33:24 GMT+0800 (中国标准时间)
console.log(newDate.toTimeString());
// Wed, 18 Jun 2014 02:33:24 GMT
console.log(newDate.toUTCString());Date.prototype.format = function(format) {var date = {"M+": this.getMonth() + 1,"d+": this.getDate(),"h+": this.getHours(),"m+": this.getMinutes(),"s+": this.getSeconds(),"q+": Math.floor((this.getMonth() + 3) / 3),"S+": this.getMilliseconds()};if (/(y+)/i.test(format)) {format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));}for (var k in date) {if (new RegExp("(" + k + ")").test(format)) {format = format.replace(RegExp.$1, RegExp.$1.length == 1? date[k] : ("00" + date[k]).substr(("" + date[k]).length));}}return format;
}
console.log(newDate.format('yyyy-MM-dd h:m:s'));</script>

转载于:https://www.cnblogs.com/SharkChilli/p/8989281.html

linux时间字符串转正常时间相关推荐

  1. pandas使用to_datetime函数将时间字符串转化为时间对象、使用dt.tz_localize为转化后的时间对象添加时区信息(timezone)

    pandas使用to_datetime函数将时间字符串转化为时间对象.使用dt.tz_localize为转化后的时间对象添加时区信息(timezone) 目录 pandas使用to_datetime函 ...

  2. pandas使用to_datetime函数将时间字符串转化为时间对象、其中月份内容为字母而非数字(例如,“January 2, 2022“)

    pandas使用to_datetime函数将时间字符串转化为时间对象.其中月份内容为字母而非数字(例如,"January 2, 2022") 目录 pandas使用to_datet ...

  3. java 字符串转utc时间_JAVA 本地时间字符串转UTC时间字符串

    本来想偷懒百度一个时间字符串转UTC的代码,但发现没有一个能用,写得还复杂得要死,没办法还是自己撸一个. /** * UTC时间字符串转本地时间字符串 * 我的本地getDateTimeInstanc ...

  4. 时间字符串string转换为时间格式nsdate

    废话不多说直接贴代码: 一.字符串转时间格式 //字符串转换为日期// 实例化NSDateFormatterNSDateFormatter *inputFormatter= [[NSDateForma ...

  5. python 当前时间字符串,Python常用时间操作总结【取得当前时间、时间函数、应用等】...

    本文实例讲述了Python常用时间操作.分享给大家供大家参考,具体如下: 我们先导入必须用到的一个module >>> import time 设置一个时间的格式,下面会用到 > ...

  6. 时间字符串与当前时间比較

    /*获得当前时间*/     public static String getCurrentTime(){         Date currentTime = new Date();         ...

  7. linux 字符串时间转换,Linux C/C++时间字符串与time_t之间的转换方法(转)

    js 获取小数点位数方法及 字符串与数字之间相互转换方法 1.获取小数点位数方法 a. 使用 js 中 subsrting,indexOf,parseFloat三个函数,代码如下: var s = & ...

  8. js 把字符串格式化成时间

    一 需求 js里面的Date.parse() 方法接收字符串,返回一个时间,但是接收的字符串格式缺不能指定,这很蛋疼,这样就有了浏览器差异,所以需要一个可以指定字符串格式的方法,将时间字符串转化为时间 ...

  9. golang时间字符串和时间戳转换

    1. 获取当前时间字符串和时间戳 package mainimport ("fmt""time" )func main() {now := time.Now() ...

最新文章

  1. RocketMq是什么
  2. Windows Azure Virtual Machine (30) 修改Azure VM 的Subnet
  3. mysql-5.2 lib_Centos 5.2下安装多个mysql数据库配置详解
  4. centos java程序_刚得到一台centos7服务器,作为Java程序员应该做的事
  5. matlab z变换离散化_MATLAB作图从入门到熟练
  6. 正确的工作流程:我应该使用哪个OAuth 2.0流程?
  7. 对JSON的一点认识和理解以及JQuery处理JSON
  8. 软件可靠性指标mtbf测试评估,软件可靠性评估.pdf
  9. MyEclipse下XFire开发Webservice实例
  10. MNews 1.9 – 干净的新闻自媒体博客wordpress主题
  11. OSError: [WinError 126] 找不到指定的模块。【专治疑难杂症】
  12. 实时计算storm流程架构总结
  13. 正则表达式的几种字符判断(包括数字,字母组合等)
  14. php数据多层关联,php – 我们如何进行laravel多级关联
  15. efl是什么意思_efl是什么意思
  16. [玩转UE4/UE5动画系统>技能系统(GAS)篇] 二 技能 Gameplay Ability(GA)
  17. Linux驱动BSP(I2C 驱动实验)
  18. FLV科普2 FLV相关工具FlvParse
  19. 3G到底有多快 三家运营商3G网速大比拼
  20. Vaa3D并行程序测试-OPENMP-VS2010-加速程序

热门文章

  1. k8s pod重启策略:Always、OnFailure、Never配置示例
  2. nfs数据同步备份:多节点nfs共享(mount)server节点数据
  3. ribbon负载均衡@LoadBalanced
  4. Spring MVC架构流程(请求处理流程)
  5. MYSQL分页limit速度太慢优化方法
  6. Java栈内存溢出代码实例
  7. eclipse报jvm terminated.exitcode=2错误的解决方法
  8. vim设置显示行号,vim跳转到文件头,文件尾
  9. 吃下去的东西老是往上翻上来_这间日日火爆的面馆,当年海藻带宋思明吃过
  10. Intellij IDEA 2019 自动生成 serialVersionUID