关于javascript中时间格式和时间戳的转换
当前时间获取的各种函数:
var myDate = new Date();
myDate.getYear(); //获取当前年份(2位),已经不推荐使用
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate(); //获取当前日(1-31)
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
myDate.getHours(); //获取当前小时数(0-23)
myDate.getMinutes(); //获取当前分钟数(0-59)
myDate.getSeconds(); //获取当前秒数(0-59)
myDate.getMilliseconds(); //获取当前毫秒数(0-999)
myDate.toLocaleDateString(); //获取当前日期
var mytime=myDate.toLocaleTimeString(); //获取当前时间
myDate.toLocaleString( ); //获取日期与时间
获得时间戳
// 获取当前时间戳(以s为单位) var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
// 获取某个时间格式的时间戳
var stringTime = "2014-07-10 10:21:12";
var timestamp2 = Date.parse(new Date(stringTime));
timestamp2 = timestamp2 / 1000;
/ 将当前时间换成时间格式字符串
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());
关于javascript中时间格式和时间戳的转换的更多相关文章
- javascript中日期格式与时间戳之间的转化
日期格式与时间戳之间的转化 一:日期格式转化为时间戳 function timeTodate(date) { var new_str = date.replace(/:/g,'-'); new_str ...
- 解决IIS7、IIS7.5中时间格式显示的问题
今天在用IIS7的时候发现一个关于时间格式的问题,当我在ASP中使用now()时间函数的时候,日期是以"/"来分隔,而不是以"-"来分隔的,使得我在运行程序的时 ...
- JS时间格式和时间戳的互转
//时间格式转为时间戳 function sjc(){ var date = new Date(); //时间对象 var str = date.getTime(); //转换成时间戳 } //时间戳 ...
- 修改springfox-swagger源码,使example中时间格式默认为“yyyy-MM-dd HH:mm:ss”
修改swagger源码,使example中时间格式默认为"yyyy-MM-dd HH:mm:ss" 前言 简单点说,在swagger中,怎么能针对以下vo中的java.util.D ...
- oracle中时间格式时候的大于号是大于和等于的意思
oracle中时间格式时候的大于号是大于和等于的意思
- 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换
var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...
- Java中时间格式处理,指定N天/小时等之后的时间
1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...
- 如何解决前端传来的时间格式与mysql表中时间格式不匹配的查询问题
前端传过来的时间格式为“2016-07-11 11:13:10”,而数据表中对应字段`add_time`的格式为“2016-7-11”,此时sql不能直接用 "where `add_time ...
- python中时间格式
问题:通过MySQLdb查询datetime字段,然后通过浏览器显示出来,得到的格式是: 'Thu, 19 Feb 2009 16:00:07 GMT' (http呈现出来的格式) ...
随机推荐
- CodeForces 408E Curious Array(组合数学+差分)
You've got an array consisting of n integers: a[1], a[2], ..., a[n]. Moreover, there are m queries, ...
- 我的Linux主机操作记录续
6.安装部署node.js环境 (1)node.js的使用的项目构建工具GYP(Generate Your Project)是基于Python2.7的,所以需要安装Python2.7环境 一般自带有此 ...
- Android-ContentProvider原理图
ContentProvider的设计思想是模仿了Web里面的架构思想: Web服务器 对外暴露数据(提供被访问的地址Uri,并允许给客户端访问,也可以只让客户端访问某些行为) ContentPro ...
- Reporting Service服务SharePoint集成模式安装配置(9、PowerPivot for SharePoint 安装配置详细)
PowerPivot for SharePoint 增加了对发布到 SharePoint 中的 PowerPivot 工作簿的协作和文档管理支持. PowerPivot for SharePoint ...
- Huawei .V3 Extention audio Play
相关dll下载 链接 using System;using System.IO;using System.Threading;using Alvas.Audio;using NAudio.Wave; ...
- IOC简洁说明
what is ioc: 控制注入,是一种设计模式 the benefits of using this: 降低耦合度 什么是DI 什么是依赖? 当一个类需要另一个类协作来完成工作的时候就产生了依赖 ...
- bitcoin script
P2PK P2PKH,MS,P2SH,OP_RETURN 等的区别 1.P2PK pay_to_public_key pubkey script: <pubkey> OP_CHECKSIG ...
- 接口文档神器Swagger(上篇)
本文来自网易云社区 作者:李哲 接口文档管理一直是一个让人头疼的问题,伴随着各种接口文档管理平台涌现,如阿里开源的rap,ShowDoc,sosoapi,等等(网上能找到很多这种管理平台,包括我们自己 ...
- 【English】20190430
Network security网络安全[ˈnetwɜːrk] [sɪˈkjʊrəti] Teradata Generic Security Service 通用安全服务[dʒəˈnerɪk] [s ...
- mongodb 的基本操作
1. show dbs 查看服务器中有多少个数据库 2.创建数据库 use <数据库名称> 注意如果数据库中没有表的话,那么数据库是不会显示的 如果存在这个表名则是切换 不存在则是 ...