js本地时间格式化
var myDate = new Date(); //获取当前时间及日期
var year=myDate.getYear(); // 获取当前年份(当前年份-1900)
var fyear=myDate.getFullYear(); // 获取完整的年份(4位,1970-????)
var mon=myDate.getMonth(); // 获取当前月份(0-11,0代表1月)
var date=myDate.getDate(); // 获取当前日(1-31)
var day=myDate.getDay(); // 获取当前星期X(0-6,0代表星期天)
var time=myDate.getTime(); // 获取当前时间(从1970.1.1开始的毫秒数)
var hos=myDate.getHours(); // 获取当前小时数(0-23)
var min=myDate.getMinutes(); // 获取当前分钟数(0-59)
var sec=myDate.getSeconds(); // 获取当前秒数(0-59)
var secs=myDate.getMilliseconds(); // 获取当前毫秒数(0-999)
var dd=myDate.toLocaleDateString(); // 获取当前日期
var mytime=myDate.toLocaleTimeString(); // 获取当前时间
var str=myDate.toLocaleString( ); // 获取日期与时间
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, // 月份
"d+": this.getDate(), // 日
"h+": this.getHours(), // 小时
"m+": this.getMinutes(), // 分
"s+": this.getSeconds(), // 秒
"q+": Math.floor((this.getMonth() + 3) / 3), // 季度
"S": this.getMilliseconds() // 毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
var time1 = new Date().Format("yyyy-MM-dd");
var time2 = new Date().Format("yyyy-MM-dd hh:mm:ss");
js本地时间格式化的更多相关文章
- js Date 时间格式化的扩展
js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...
- js -- 日期时间格式化
/** * js日期时间格式化 * @param date 时间读对象 * @param format 格式化字符串 例如:yyyy年MM月dd日 hh时mm分ss秒 * @returns {stri ...
- js 中时间格式化的几种方法
1.项目中时间返回值,很过时候为毫秒值,我们需要转换成 能够看懂的时间的格式: 例如: yyyy-MM-dd HH:mm:ss 2.处理方法(处理方法有多种,可以传值到前端处理,也可以后台可以好之后再 ...
- 用JavaScript(js)对时间格式化
Date.prototype.format =function(format) { var o = { "M+" : (this.getMo ...
- JS 自定义时间格式化
// 对Date的扩展,将 Date 转化为指定格式的String// 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位 ...
- js获取时间格式化
http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
- JS日期时间格式化
Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...
- JS Date 时间格式化
Date2Str(x, y) { , d: x.getDate(), h: x.getHours(), m: x.getMinutes(), s: x.getSeconds() }; y = y.re ...
- JS前端时间格式化
var dateTime = new Date(tree_time); tree_time = dateTime.getFullYear() + '-'+ (dateTime.getMonth()+1 ...
随机推荐
- mv 移动或重命名文件
1. 命令功能 mv:移动或改文件名 2. 语法格式 mv [option] source dest mv 选项 源文件 目标文件 参数 参数说明 -f 如果目标文件存在,则不会询问而是直接覆 ...
- 解决 INSTALL FAILED CONFLICTING PROVIDER
1.现象: 2.产生原因 INSTALL FAILED CONFLICTING PROVIDER 产生的原因通常是因为系统中已经安装的apk的provider中的authorities相同了,导致在安 ...
- Mybatis之:SqlSessionFactory、SqlSession
public class CountryMapperTest { private static SqlSessionFactory sqlSessionFactory; @BeforeClass pu ...
- NASA CEA 安装指南
有用的网站: http://www.engr.colostate.edu/~marchese/combustion08/cec.html 1 把三个压缩包解压到同一个Ubuntu文件夹CEAexec下 ...
- python绘制图的度分布柱状图, draw graph degree histogram with Python
图的度数分布 import collections import matplotlib.pyplot as plt import networkx as nx G = nx.gnp_random_gr ...
- 策略模式优化过多的IF ELSE
前言: 当if else的条件少的话,代码可阅读性及逻辑不影响阅读和扩展.一旦if else过多的话会导致逻辑比较混乱,不易扩展并且很容易出错. 实现方案: 1.定义一个@HandlerType注解, ...
- Hadoop 学习目录(搁置)
简介 Hadoop是一个由Apache基金会所开发的分布式系统基础架构.用户可以在不了解分布式底层细节的情况下,开发分布式程序.充分利用集群的威力进行高速运算和存储.Hadoop实现了一个分布式文件系 ...
- ckeditor富文本编辑器的使用和图片上传,复制粘贴图片上传
自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...
- luoguP4721 【模板】分治 FFT (分治NTT)
给定 $g[1....n-1]$,求 $f[0],f[1],...,f[n-1]$,其中 $f[i]=\sum_{j=1}^{i}f[i-j]g[j]$ 变界为 $f[0]=1$ 答案模 9 ...
- [STL]lower_bound&upper_bound
源码 lower_bound template <class ForwardIterator, class T> ForwardIterator lower_bound (ForwardI ...