当前位置:网站首页>Custom time format (yyyy-mm-dd HH: mm: SS week x)
Custom time format (yyyy-mm-dd HH: mm: SS week x)
2022-04-23 07:45:00 【Senior salted fish~】
<script>
function format(newDate) {
var day = newDate.getDay()
var y = newDate.getFullYear()
var m = (newDate.getMonth() + 1) < 10 ? "0" + (newDate.getMonth() + 1) : (newDate.getMonth() + 1)
var d = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate()
var h = newDate.getHours() < 10 ? "0" + newDate.getHours() : newDate.getHours()
var min = newDate.getMinutes() < 10 ? "0" + newDate.getMinutes() : newDate.getMinutes()
var s = newDate.getSeconds() < 10 ? "0" + newDate.getSeconds() : newDate.getSeconds()
var dict = {
1: " One ",
2: " Two ",
3: " 3、 ... and ",
4: " Four ",
5: " 5、 ... and ",
6: " 6、 ... and ",
0: " God ",
}
//var week=[" Japan "," One "," Two "," 3、 ... and "," Four "," 5、 ... and "," 6、 ... and "]
return y + "-" + m + "-" + d + " " + h + ":" + min + ":" + s + " week " + dict[day]
}
var newDate = new Date()
console.log(format(newDate))
</script>
Be careful :
One 、date.getDay() The result is a number 0-6,0 Corresponding to Sunday 、1-6 Corresponds to Monday to Saturday
Convert numbers to chinese , There are two ways :
(1) Dictionaries var dict = {
1: " One ",
2: " Two ",
3: " 3、 ... and ",
4: " Four ",
5: " 5、 ... and ",
6: " 6、 ... and ",
0: " God ",
}
Use :dict[date.getDay()]
(2) Array var week=[" Japan "," One "," Two "," 3、 ... and "," Four "," 5、 ... and "," 6、 ... and "]
Use :week[date.getDay()]
Two 、date.getMonth() Month obtained +1 It's the real month
Print the results
版权声明
本文为[Senior salted fish~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230623087213.html
边栏推荐
猜你喜欢
随机推荐
AuthorizationServer(授权服务器的简单搭建)
SAP PI/PO Soap2Proxy 消费外部ws示例
SAP TRANSLATE使用数据对象掩码示例
反思 | Android 音视频缓存机制的系统性设计
Thorough inquiry -- understanding and analysis of cocos2d source code
每日一题 | 曾被反转链表支配的恐惧
8. Paging query
Processing of common dependency module
js之DOM学习三种创建元素的方式
Authorization+Token+JWT
3. Sort statement
Understanding of STL container
Hot change scheme and dynamic update strategy of mobile game
MySQL index
6. Aggregation function and grouping statistics
[hdu6833]A Very Easy Math Problem(莫比乌斯反演)
MySQL isolation level
instanceof的实现原理
js中对象的三种创建方式
斐波拉去动态规划