js获取当前时间方法
AI 概述
js 获取当前时间
html 代码
<div id="current"></div>
JS 代码
$("#current").html(currentDate(true, true))
/*
type:true(格式:2018 年 01 月 01 日)
false(格式:2018-01-01)
isno: true(包含时分秒:2018-01-01 01:01:01)
false(不包含时分秒:2018-01-01)
*/
function currentDate...
js 获取当前时间
html 代码
<div id="current"></div>
JS 代码
$("#current").html(currentDate(true, true))
/*
type:true(格式:2018 年 01 月 01 日)
false(格式:2018-01-01)
isno: true(包含时分秒:2018-01-01 01:01:01)
false(不包含时分秒:2018-01-01)
*/
function currentDate(type, isno) {
var date = new Date();
var year = singular(date.getFullYear());
var month = singular(date.getMonth() + 1);
var strDate = singular(date.getDate());
var hours = singular(date.getHours());
var minutes = singular(date.getMinutes());
var seconds = singular(date.getSeconds());
if (type) {
if (isno) {
return year + "年" + month + "月" + strDate + "日 " + hours + "时" + minutes + "分" + seconds + "秒";
} else {
return year + "年" + month + "月" + strDate + "日";
}
} else {
if (isno) {
return year + "-" + month + "-" + strDate + " " + hours + ":" + minutes + ":" + seconds;
} else {
return year + "-" + month + "-" + strDate;
}
}
}
// 单数补位
function singular(num) {
if (num < 10) {
num = "0" + num;
}
return num;
}
以上关于js获取当前时间方法的文章就介绍到这了,更多相关内容请搜索码云笔记以前的文章或继续浏览下面的相关文章,希望大家以后多多支持码云笔记。
声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 admin@mybj123.com 进行投诉反馈,一经查实,立即处理!
重要:如软件存在付费、会员、充值等,均属软件开发者或所属公司行为,与本站无关,网友需自行判断
码云笔记 » js获取当前时间方法
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 admin@mybj123.com 进行投诉反馈,一经查实,立即处理!
重要:如软件存在付费、会员、充值等,均属软件开发者或所属公司行为,与本站无关,网友需自行判断
码云笔记 » js获取当前时间方法

微信
支付宝