[学习笔记]JS获取当前日期,年月日
来源:互联网 发布:php 访问sqlserver 编辑:程序博客网 时间:2024/06/09 13:52
第一种方法:
function CurentTimeMonth()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month;
return (clock);
}
第二种方法:
function formatDate() {
var d=new Date(); // 获取当前日期
var m=d.getMonth()+1;
if(m<10){
m="0"+m;
}
var day=d.getDate();
if(day<10){
day="0"+day;
}
var str=d.getYear()+"-"+(m)+"-"+day+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
return str;
}
function CurentTimeMonth()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month;
return (clock);
}
第二种方法:
function formatDate() {
var d=new Date(); // 获取当前日期
var m=d.getMonth()+1;
if(m<10){
m="0"+m;
}
var day=d.getDate();
if(day<10){
day="0"+day;
}
var str=d.getYear()+"-"+(m)+"-"+day+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
return str;
}
0 0
- [学习笔记]JS获取当前日期,年月日
- js获取当前时间,日期格式为年月日
- js 获取当前时间 年月日
- js 获取当前时间 年月日
- js中的getDate() getMonth() getFullYear()方法;js如何获取当前日期/年月日
- js 获取当前年月日时分秒星期
- js 获取当前年月日时分秒星期
- JS获取当前时间年月日时分秒
- js 获取当前年月日时分秒星期
- JS获取当前时间,年月日时
- js 当前获取时间 年月日 星期几
- Js 获取当前日期
- js 获取当前日期
- JS获取当前日期
- js获取当前日期
- js 获取当前日期
- js获取当前日期
- js获取当前日期
- LeetCode之19---Remove Nth Node From End of List
- 消息中间件(一)JMS与ActiveMQ
- 分治-二分查找
- Java中关于异常的一些问题(二)
- HTTP 访问接口封装,app开发中常用
- [学习笔记]JS获取当前日期,年月日
- APM四轴组装调试记录
- commons-csv读写CSV文件
- [学习笔记]window.showModalDialog窗口跳转取值
- PullToRefresh使用详解--构建下拉刷新的listView
- 【天道酬勤】 腾讯、百度、网易游戏、华为Offer及笔经面经
- [学习笔记]File类简单用法!
- 计数排序
- PHP表单处理