Js获取当前的日期和时间以及时间戳转化为时间
2024-08-28 21:32:50
/**
*获取当前时间
*format=1精确到天
*format=2精确到分
*/
function getCurrentDate(format) {
var now = new Date();
var year = now.getFullYear(); //得到年份
var month = now.getMonth();//得到月份
var date = now.getDate();//得到日期
var day = now.getDay();//得到周几
var hour = now.getHours();//得到小时
var minu = now.getMinutes();//得到分钟
var sec = now.getSeconds();//得到秒
month = month + 1;
if (month < 10) month = "0" + month;
if (date < 10) date = "0" + date;
if (hour < 10) hour = "0" + hour;
if (minu < 10) minu = "0" + minu;
if (sec < 10) sec = "0" + sec;
var time = "";
//精确到天
if(format==1){
time = year + "-" + month + "-" + date;
}
//精确到分
else if(format==2){
time = year + "-" + month + "-" + date+ " " + hour + ":" + minu + ":" + sec;
}
return time;
}
alert(getCurrentDate(2));
最新文章
- java基础算法之快速排序
- pptv泥够了!pptv“关闭”事件为营销炒作坐实!
- 【Web】URI和URL,及URL的编码
- 记一次ganglia的故障分析 mem_report不显示
- windows2003开启vpn服务
- 微信端应用 ionic实现texarea 自适应高度
- Online Object Tracking: A Benchmark 翻译
- A+B问题 涉及EOF
- jQuery设计思想
- 每天一道LeetCode--237.Delete Node in a Linked List
- Office 365 – Exchange Online examples
- 二维离散平稳小波分解swt2
- api接口json串换行
- 快速找到Office应用程序安装路径
- 事件的preventDefault方法
- KVM管理平台openebula安装
- lightoj 1025 区间dp
- django——url(路由)配置
- input上传文件个数控制
- CString、string、const char*的相互转换
热门文章
- gradlew tasks
- 无法远程连接阿里云的Mysql
- css(4)
- html5--2.9新的布局元素(6)-figure/figcaption
- python3 - 写一个生成双色球号码的一个程序,生成的号码写到文件里面
- C语言的内存四区模型和函数调用模型
- [CTSC 2012] Cheat
- AtCoder Regular Contest 080 E:Young Maids
- BZOJ4571:[SCOI2016]美味
- CF 504 E —— Misha and LCP on Tree —— 树剖+后缀数组