//获取当前时间:
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. How to Avoid Producing Legacy Code at the Speed of Typing

    英语不好翻译很烂.英语好的去看原文. About the Author I am a software architect/developer/programmer.I have a rather p ...

  2. activity的生命周期详解

    刚在看mars老师的视频,看到activity的生命周期,就看了一下,总结了一下.下面是各函数的调用时机 为了更清楚的看清楚工作的具体过程,举例如下: ,建立两个activity,一个main,一个a ...

  3. MySQL实用基础笔记

    /* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限验证登录MySQL */ mysq ...

  4. Toast添加动画

    WindowManger wm =(WindowManger)context.getSystemService(Context.WINDOW_SERVICE); View view = Toast.m ...

  5. python基础教程第6章——抽象

    1.函数的定义,使用def(或“函数定义”)语句: def hello(name): return ‘Hello.'+name+'!' def fibs(num): result=[0,1] for ...

  6. rsyslog 同时发生nginx 访问日志和错误日志

    input(type="imfile" File="/var/log/nginx/access.log" Tag="zjzc-frontend01-a ...

  7. Boost库学习之旅入门篇

    学习及使用Boost库已经有一段时间了,Boost为我的日常开发中带来了极大的方便,也使得我越来越依赖于boost库了.但boost功能太多,每次使用还是得翻看以前的 资料,所以为了以后可以更方便的使 ...

  8. 消息提示demo

    我们做网站,经常会遇到消息提示. 我仿照腾讯的邮箱做了个小demo. 提示出现后,几秒消失.提示的位置是固定的.不受布局的影响. 效果如下: 提示通常分两种,一种使错误提示,一种是成功提示.用不同的c ...

  9. Make a travel blog by Blogabond the theme of wordpress

    We can record our place which we have ever went.If you want to know any more you can visit :http://w ...

  10. #include <boost/function.hpp>

    为atoi取别名fun,fun实质上是函数指针 #include <iostream> #include <boost/function.hpp> void main() { ...