JS 时间格式化,模拟PHP date,时间格式化封装函数
Date.prototype.Format = function (fmt) {
var o = {
"Y": this.getFullYear(),
"m": this.getMonth() + 1,
"d": this.getDate()<10?'0'+this.getDate():this.getDate(),
"H": this.getHours()<10?'0'+this.getHours():this.getHours(),
"i": this.getMinutes()<10?'0'+this.getMinutes():this.getMinutes(),
"s": this.getSeconds()<10?'0'+this.getSeconds():this.getSeconds(),
};
for (var k in o){
if (fmt.indexOf(k) > -1) {
fmt = fmt.replace(new RegExp("(" + k + ")"),o[k]);
}
}
return fmt;
}
使用方法 (new Date()).Format('Y-m-d H:i:s') 输出 2018-12-07 15:30:00 格式时间
JS 时间格式化,模拟PHP date,时间格式化封装函数的更多相关文章
- Linux重定向输出到以当前时间命名的文件 / date命令格式化输出
1. 利用date命令重定向到以当前时间命名的文件 例如: ls -l > mylog_$(date +"%Y-%m-%d_%H-%M-%S").log 或: ls -l & ...
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- JS获取当前日期和时间的方法,并按照YYYY-MM-DD格式化
Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); ...
- js Date 日期格式化(转)
var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1 ...
- javascript Date 日期格式化 formatDate, require.js 模块 支持全局js引入 / amd方式加载
* 引入AMD加载方式: require.js CDN https://cdn.bootcss.com/require.js/2.3.5/require.js * 创建模块文件./js/util/d ...
- C标准函数库中获取时间与日期、对时间与日期数据操作及格式化
表示时间的三种数据类型[编辑] 日历时间(calendar time),是从一个标准时间点(epoch)到现在的时间经过的秒数,不包括插入闰秒对时间的调整.开始计时的标准时间点,各种编译器一般使用19 ...
- Java日期工具类,Java时间工具类,Java时间格式化
Java日期工具类,Java时间工具类,Java时间格式化 >>>>>>>>>>>>>>>>>&g ...
- Java-Runoob-高级教程-实例-时间处理:01. Java 实例 - 格式化时间(SimpleDateFormat)
ylbtech-Java-Runoob-高级教程-实例-时间处理:01. Java 实例 - 格式化时间(SimpleDateFormat) 1.返回顶部 1. Java 实例 - 格式化时间(Sim ...
- [java工具类01]__构建格式化输出日期和时间的工具类
在之前的学习中,我写过一篇关于字符串格式化的,就主要设计到了时间以及日期的各种格式化显示的设置,其主要时通过String类的fomat()方法实现的. 我们可以通过使用不同的转换符来实现格式化显示不同 ...
- Java如何格式化AM-PM格式的时间?
在JAVA中,如何格式化AM-PM格式的时间? 该示例使用SimpleDateFormat(“HH-mm-ss a”)构造函数和SimpleDateFormat类的sdf.format(date)方法 ...
随机推荐
- 利用canvas来绘制一个会动的图画,欢迎指教
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- linux常用命令(50个)
1. find 基本语法参数如下: find [PATH] [option] [action] # 与时间有关的参数: -mtime n : n为数字,意思为在n天之前的“一天内”被更改过的文件: - ...
- 关于“为什么不加friend就会提示参数过多”
#include <iostream> using namespace std; class Complex { double real, imag; public: Complex(do ...
- 【Leetcode】【Medium】Linked List Cycle
Given a linked list, determine if it has a cycle in it. 解题: 判断单链表是否具有环,使用两个指针once和twice遍历链表,once一次走一 ...
- January 27 2017 Week 4 Friday
Procrastination is the thief of time. 拖延是时光之贼. Procrastination is the thief of time, besides, it is ...
- She must be at least thirty-five years old.
She must be at least thirty-five years old. Though life's goodness can at times be overshadowed,it i ...
- OC NSMutableArray
#import <Foundation/Foundation.h> #import "Student.h" void arrayCreate() { NSMutable ...
- 六种排序算法的JavaScript实现以及总结
最近几天在系统的复习排序算法,之前都没有系统性的学习过,也没有留下过什么笔记,所以很快就忘了,这次好好地学习一下. 首先说明为了减少限制,以下代码通通运行于Node V8引擎而非浏览器,源码在我的Gi ...
- 防护XSS
http://blog.csdn.net/kouwoo/article/details/41946683 http://www.2cto.com/article/201309/247100.html ...
- Perl中的字符串操作函数
1.$position = index(string,substring,skipchars): 该函数返回子串substring在字符串string中的位置,如果不存在,则返回-1:参数skipch ...