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本地时间格式化的更多相关文章

  1. js Date 时间格式化的扩展

    js Date 时间格式化的扩展: Date.prototype.format = function (fmt) { var o = { , //月 "d+": this.getD ...

  2. js -- 日期时间格式化

    /** * js日期时间格式化 * @param date 时间读对象 * @param format 格式化字符串 例如:yyyy年MM月dd日 hh时mm分ss秒 * @returns {stri ...

  3. js 中时间格式化的几种方法

    1.项目中时间返回值,很过时候为毫秒值,我们需要转换成 能够看懂的时间的格式: 例如: yyyy-MM-dd HH:mm:ss 2.处理方法(处理方法有多种,可以传值到前端处理,也可以后台可以好之后再 ...

  4. 用JavaScript(js)对时间格式化

    Date.prototype.format =function(format)     {         var o = {         "M+" : (this.getMo ...

  5. JS 自定义时间格式化

    // 对Date的扩展,将 Date 转化为指定格式的String// 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位 ...

  6. js获取时间格式化

    http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html

  7. JS日期时间格式化

    Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...

  8. JS Date 时间格式化

    Date2Str(x, y) { , d: x.getDate(), h: x.getHours(), m: x.getMinutes(), s: x.getSeconds() }; y = y.re ...

  9. JS前端时间格式化

    var dateTime = new Date(tree_time); tree_time = dateTime.getFullYear() + '-'+ (dateTime.getMonth()+1 ...

随机推荐

  1. 2018ICPC银川 L Continuous Intervals 单调栈 线段树

    题意:给你一个序列,问你这个序列有多少个子区间,满足把区间里的数排序之后相邻两个数之间的差 <= 1 ? 思路:https://blog.csdn.net/u013534123/article/ ...

  2. python 的三元运算符

    一.三元运算符 三元运算符就是在赋值变量的时候,可以直接加判断,然后赋值 格式:[on_true] if [expression] else [on_false] res = 值1 if 条件 els ...

  3. Ubuntu 18.04 安装 Octave 5.1

    最新版目前只能通过编译安装.折腾了半天终于搞定: 需要使用apt-get install先把各种 dependencies 安装好. 编译JIT需要安装sudo apt-get install llv ...

  4. 用C语言编程乘法口诀表

    首先是全部,代码如下: #include<stdio.h> void main() { int i,j; ;i<=;i++) { ;j<=;j++) printf(" ...

  5. B/S文件断点上传

    一.概述 所谓断点续传,其实只是指下载,也就是要从文件已经下载的地方开始继续下载.在以前版本的HTTP协议是不支持断点的,HTTP/1.1开始就支持了.一般断点下载时才用到Range和Content- ...

  6. jsp选择文件夹上传

    文件夹数据库处理逻辑 publicclass DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject(); ...

  7. [USACO14MAR] 破坏Sabotage(二分答案,分数规划)

    题目链接 Solution 去掉中间一段区间 \([l,r]\) 后剩下的平均值可以表示为 : \[\frac{\sum^{n}_{i=1}{v_i}-\sum^{r}_{i=l}{v_i}}{n-( ...

  8. php函数名前添加& 函数的引用返回

    function &test(){ static $b=0; $b= $b+1; return $b; } $a= test(); echo $a,"\n"; $a = 3 ...

  9. 移动端调试 — chrome模拟器基础调试

    打开开发者工具,进入chrome调试状态,点击左上角的手机图标,进入手机模拟器调试状态. 模拟器支持操作: 切换设备类型,模拟网络环境,模拟bar,keyboard弹出状态,横屏状态,更改UserAg ...

  10. ubuntu更换源

    1.备份源 cd  /etc/apt/ sudo cp sources.list sources.list.bak 2.更换阿里源 sudo vim /etc/apt/sources.list   中 ...