js如何获取当前时间代码,下面web建站小编给大家详细介绍一下具体代码!
具体代码如下:
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;
}
方法调用
console.log('输出结果:', currentDate(true, true))
//输出结果:2023年01月11日 12时59分55秒
console.log('输出结果:', currentDate(true, false))
//输出结果:2023年01月11日
console.log('输出结果:', currentDate(false, true))
//输出结果:2023-01-11 13:02:40
console.log('输出结果:', currentDate(false, false))
//输出结果:2023-01-11
上面是“js封装获取当前时间代码”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3083.html
workflows工作流
一只可爱的草莓味冰淇淋卷筒
一幅3D农场游戏画面ComfyUI工作流
小丑鱼马林在鱼缸里游来游去ComfyUI工作流
一个白色的咖啡杯,蒸汽从杯子里冒出来
文生图工作流:一幅海底睡莲,碧海蓝天comfyui工
蝴蝶兰comfyui工作流
一颗巨型的木星ComfyUI工作流
1个粉红色头发可爱的女孩ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

barcode条形码/qrcode二维码兼容所有浏览器(含ie6/ie7/ie8)
黑客入侵效果代码
canvas黑洞漩涡(canvas+js)
javascript如何利用draggable实现一个拖拽效果
css3实现星球旋转
用ascii字符画图像
如何利用css3+js做一个下雨效果











