//获取当前时间:
var myDate = new Date();//当前时间
var year = myDate.getFullYear();//当前年份
var month = myDate.getMonth() + 1;//当前月份
var day = myDate.getDate();//当前日
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( ); //获取日期与时间 var oneDay = 1000 * 60 * 60 * 24; //获取最近一周的日期
var lastDate = new Date(myDate - oneDay * 6);
var lastYear = lastDate.getFullYear();
var lastMonth = lastDate.getMonth() + 1;
var lastDay = lastDate.getDate(); //获取当前月的最后一天
var day = new Date(year ,month , 0);
var lastdate = day.getDate();//当前月的最后一天 //获取最近N个月的日期
var lastDate = new Date(myDate - oneDay * myDate.getDate());
lastDate = new Date(lastDate - N * oneDay * (lastDate.getDate() - 1));
var lastYear = lastDate.getFullYear();
var lastMonth = lastDate.getMonth() + 1;
var lastDay = lastDate.getDate(); //字符串转换为时间戳
var date="2014-12-06";
date = new Date(Date.parse(date.replace(/-/g, "/")));
date = date.getTime();

js获取时间和日期,字符串和时间戳之间的转换的更多相关文章

  1. JS 时间字符串与时间戳之间的转换

    1.当前时间换时间戳 var timestamp = parseInt(new Date().getTime()/1000); // 当前时间戳 document.write(timestamp); ...

  2. python 时间字符串和时间戳之间的转换

    https://blog.csdn.net/qq_37193537/article/details/78987949   1.将字符串的时间转换为时间戳    方法:        a = " ...

  3. js时间和时间戳之间如何转换(汇总)

    js时间和时间戳之间如何转换(汇总) 一.总结 一句话总结: 1.js中通过new Date()来获取时间对象, 2.这个时间对象可以通过getTime()方法获取时间戳, 3.也可以通过getYea ...

  4. 常见的时间字符串与timestamp之间的转换 时间戳

    这里说的字符串不是一般意义上的字符串,是指在读取日期类型的数据时,如果还没有及时解析字符串,它就还不是日期类型,那么此时的字符串该怎么与时间戳之间进行转换呢? ① 时间字符串转化成时间戳 将时间字符串 ...

  5. js获取时间相关函数

    js获取时间函数 var myDate = new Date; var year = myDate.getFullYear();//获取当前年 var yue = myDate.getMonth()+ ...

  6. python—时间与时间戳之间的转换

    python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...

  7. javascript中日期格式与时间戳之间的转化

    日期格式与时间戳之间的转化 一:日期格式转化为时间戳 function timeTodate(date) { var new_str = date.replace(/:/g,'-'); new_str ...

  8. 字符串与Objec之间互相转换

    字符串与Objec之间互相转换可通过json实现. JSON.parse(str);// 字符串转Json Object JSON.stringify(obj);// Obj转字符串

  9. kotlin字符串和数字之间的转换和人机交互

    继续基础学习~ 字符串和数字之间的转换 那如何转换呢,其实很简单: 编译木有报错,但是运行: 所以这里了解下. 人机交互 看这标题貌似高端的,其实也就是程序可以接受键盘的输入啦,下面开始: 首先提示用 ...

随机推荐

  1. roundcute 添加修改密码插件

    添加修改密码插件 现打开main.inc.php 文件,搜索“$rcmail_config['plugins']”,找到: // List of active plugins (in plugins/ ...

  2. stl的集合set——安迪的第一个字典(摘)

    set就是数学上的集合——每个元素最多只出现一次,和sort一样,自定义类型也可以构造set,但同样必须定义“小于”运算符 以下代码测试set中无重复元素 #include<iostream&g ...

  3. C#生成缩略图的方法

    1.需要添加应用System.Drawing.dll 2.命名空间 using System.IO; using System.Drawing; using System.Drawing.Imagin ...

  4. 放大镜效果之js

    HTML代码: div.box>div#left+div#buttom+div#right div#left>img div#buttom>div.small>img CSS代 ...

  5. pat_1

    2-0 2-1 #include <stdio.h> int main() { int inch,foot,cm; scanf("%d",&cm); foot= ...

  6. 也谈谈关于WEB的感想

    距离上次在博客园发表博文已经是数年以前了,想想自己也确实有够懒惰的,实为不该. 引起我想发这篇博文的原因是 @Charlie.Zheng 所发表的 <Web系统开发构架再思考-前后端的完全分离& ...

  7. CentOS6.4 LAMP环境搭建

    网上的教程,不能按着抄打进去,这样会打乱你环境放置位置, 会导致配置路径会出问题. 要有一个环境目录优化, 把环境文件都装在/usr/local里面 首先,把安装文件rar都放置在/usr/local ...

  8. FireDAC

    http://docs.embarcadero.com/products/rad_studio/firedac/frames.html Access: http://docwiki.embarcade ...

  9. javascript 跨域汇总

    什么是跨域?当两个域具有相同的协议.相同的端口.相同的host时,那么我们就可以认为它们是相同的域.比如:http://www.example.com/a.html 和 http://www.exam ...

  10. Zepto,Zepto API 中文版,Zepto 中文手册,Zepto API,Zepto API 中文版,Zepto 中文手册,Zepto API 1.0, Zepto API 1.0 中文版,Zepto 1.0 中文手册,Zepto 1.0 API-translate by yaotaiyang

    Zepto,Zepto API 中文版,Zepto 中文手册,Zepto API,Zepto API 中文版,Zepto 中文手册,Zepto API 1.0, Zepto API 1.0 中文版,Z ...