GVKun编程网logo

怎样使用javascript Date Format方法(js date.format)

10

本文将介绍怎样使用javascriptDateFormat方法的详细情况,特别是关于jsdate.format的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉

本文将介绍怎样使用javascript Date Format方法的详细情况,特别是关于js date.format的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于Add Formatted Data to a Spreadsheet_javascript技巧、C# Xamarin Forms WebView EvaluateJavaScriptAsync 执行 javascript、fmt:formatDate的输出格式详解_javascript技巧、javascript - post上传完 返回format: request Content-Type isn''t multipart/form-data的知识。

本文目录一览:

怎样使用javascript Date Format方法(js date.format)

怎样使用javascript Date Format方法(js date.format)

这次给大家带来怎样使用javascript Date Format方法,使用javascript Date Format方法的注意事项有哪些,下面就是实战案例,一起来看一下。

方法一:

// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, 
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
// 例子: 
// (new Date()).Format(yyyy-MM-dd hh:mm:ss.S) ==> 2006-07-02 08:09:04.423 
// (new Date()).Format(yyyy-M-d h:m:s.S)      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) { //author: meizz 
    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;
}
new Date().Format(yyyy-MM-dd hh:mm:ss);
//2016-01-19 15:53:24

方法二:

<!-- /** * 对Date的扩展,将 Date 转化为指定格式的String * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q)
    可以用 1-2 个占位符 * 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) * eg: * (new
    Date()).format(yyyy-MM-dd hh:mm:ss.S)==> 2006-07-02 08:09:04.423      
 * (new Date()).format(yyyy-MM-dd E HH:mm:ss) ==> 2009-03-10 二 20:09:04      
 * (new Date()).format(yyyy-MM-dd EE hh:mm:ss) ==> 2009-03-10 周二 08:09:04      
 * (new Date()).format(yyyy-MM-dd EEE hh:mm:ss) ==> 2009-03-10 星期二 08:09:04      
 * (new Date()).format(yyyy-M-d h:m:s.S) ==> 2006-7-2 8:9:4.18      
 */        
Date.prototype.format=function(fmt) {         
    var o = {         
    M+ : this.getMonth()+1, //月份         
    d+ : this.getDate(), //日         
    h+ : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时         
    H+ : this.getHours(), //小时         
    m+ : this.getMinutes(), //分         
    s+ : this.getSeconds(), //秒         
    q+ : Math.floor((this.getMonth()+3)/3), //季度         
    S : this.getMilliseconds() //毫秒         
    };         
    var week = {         
    0 : /u65e5,         
    1 : /u4e00,         
    2 : /u4e8c,         
    3 : /u4e09,         
    4 : /u56db,         
    5 : /u4e94,         
    6 : /u516d        
    };         
    if(/(y+)/.test(fmt)){         
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+).substr(4 - RegExp.$1.length));         
    }         
    if(/(E+)/.test(fmt)){         
        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? /u661f/u671f : /u5468) : )+week[this.getDay()+]);         
    }         
    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;         
}
new Date().format(yyyy-MM-dd hh:mm:ss);
//2016-01-19 03:59:41

相信看了本文案例你已经掌握了方法,更多精彩请关注小编网其它相关文章!

推荐阅读:

如何访问JS的对象属性与方法

Ajax的工作原理核心以及对象

Add Formatted Data to a Spreadsheet_javascript技巧

Add Formatted Data to a Spreadsheet_javascript技巧

Script Code

复制代码 代码如下:

Set objExcel = CreateObject("Excel.Application") 

objExcel.Visible = True 
objExcel.Workbooks.Add 
objExcel.Cells(1, 1).Value = "Test value" 
objExcel.Cells(1, 1).Font.Bold = TRUE 
objExcel.Cells(1, 1).Font.Size = 24 
objExcel.Cells(1, 1).Font.ColorIndex = 3 

C# Xamarin Forms WebView EvaluateJavaScriptAsync 执行 javascript

C# Xamarin Forms WebView EvaluateJavaScriptAsync 执行 javascript

好的,感谢 Jason,我设法得到了一些好的指导并让它发挥了作用。 实际上,getElementsByClassName“返回所有子元素的类数组对象”。 由于它是一个数组,只需在单击之前选择数组的第一个元素即可。

var result = await wbView1.EvaluateJavaScriptAsync("document.getElementsByClassName('load_more_btn ib')[0].click();");

fmt:formatDate的输出格式详解_javascript技巧

fmt:formatDate的输出格式详解_javascript技巧


2004-5-31 23:59:59


2004-4-1


23:59:59


2004-5-31


04-5-31


2004-5-31


2004年5月31日


2004年5月31日 星期一


23:59:59


下午11:59


23:59:59


下午11时59分59秒


下午11时59分59秒 CDT


星期四, 四月 1, 2004 13:30:00 -0600

h   12   小时制的小时。一位数的小时数没有前导零。   
  hh   12   小时制的小时。一位数的小时数有前导零。   
  H   24   小时制的小时。一位数的小时数没有前导零。   
  HH   24   小时制的小时。一位数的小时数有前导零。    
  m   分钟。一位数的分钟数没有前导零。   
  mm   分钟。一位数的分钟数有一个前导零。   
  s   秒。一位数的秒数没有前导零。   
  ss   秒。一位数的秒数有一个前导零。

  对于0点显示的结果不一样

要求${date}为date类型如果为String 就用

<script>document.write("${l.inputDate}".substring(0, 10));</script>






My JSP ''fmt.jsp'' starting page





currency:

percent:





full-->

long-->

medium-->

default-->

short-->


今天是:

现在是:
结果:
今天是:公元 2007年10月19日 星期五
现在是:下午 20:04:11.484 CST


The input parameters must match the patterns, or the JSP will thrown an exception. This page does no error handling.

Input parameters:
Date: 2004/04/01:13:30:00 Java format: Thu Apr 01 13:30:00 CST 2004
isoDate: 20040531T235959 Java format: Mon May 31 23:59:59 CDT 2004

Dates
Tag Output
Attribute: value; required. Tag has no body.

2004-4-1 13:30:00

2004-5-31 23:59:59
Attribute: type; optional. Indicates what to print: date, time, or both.

2004-4-1

23:59:59
Attribute: dateStyle; optional. Varies the date format.

2004-5-31

04-5-31

2004-5-31

2004年5月31日

2004年5月31日 星期一
Attribute: timeStyle; optional. Varies the time format.

23:59:59

下午11:59

23:59:59

下午11时59分59秒

下午11时59分59秒 CDT
Attribute: pattern; optional. Inidcates date/time custom patterns.

星期四, 四月 1, 2004 13:30:00 -0600

javascript - post上传完 返回format: request Content-Type isn''t multipart/form-data

javascript - post上传完 返回format: request Content-Type isn''t multipart/form-data

post上传mp3完 返回错误文本是这个
{"error":"invalid multipart format: request content-type isn''t multipart/form-data"}

这是哪里的错误 好像说的是说:内容类型不是multipart/form-data”的意思

回复内容:

post上传mp3完 返回错误文本是这个
{"error":"invalid multipart format: request content-type isn''t multipart/form-data"}

这是哪里的错误 好像说的是说:内容类型不是multipart/form-data”的意思

你在包头没有写入content-type类型。 建议抓下包看下,或是用浏览器的调试模式看下

立即学习“Java免费学习笔记(深入)”;

上传文件要指定Content-Type,比如php用curl上传文件
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$data 需要为数组,而不是字符串

我们今天的关于怎样使用javascript Date Format方法js date.format的分享就到这里,谢谢您的阅读,如果想了解更多关于Add Formatted Data to a Spreadsheet_javascript技巧、C# Xamarin Forms WebView EvaluateJavaScriptAsync 执行 javascript、fmt:formatDate的输出格式详解_javascript技巧、javascript - post上传完 返回format: request Content-Type isn''t multipart/form-data的相关信息,可以在本站进行搜索。

本文标签:

上一篇使用HTML5 Canvas为图片填充颜色和纹理(canvas填充颜色的属性)

下一篇HTML5 Canvas绘制时指定颜色与透明度的方法(canvas设置透明色)