如何在Jquery中更改Dateformat?

时间:2016-01-06 12:40:45

标签: jquery

我在jQuery中获得了Date,但这是06-01-2016格式,但我只想unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type _cpinfoex = record MaxCharSize: UINT; { max length (bytes) of a char } DefaultChar: array[0..MAX_DEFAULTCHAR - 1] of Byte; { default character } LeadByte: array[0..MAX_LEADBYTES - 1] of Byte; { lead byte ranges } UnicodeDefaultChar : WCHAR; CodePage : UINT; CodePageName : array[0..MAX_PATH] of char; end; TCPInfoEx = _cpinfoex; {$EXTERNALSYM CPINFOEX} CPINFOEX = _cpinfoex; {$EXTERNALSYM GetCPInfoEx} TForm1 = class(TForm) procedure FormShow(Sender: TObject); private procedure Check; public end; function GetCPInfoEx(CodePage: UINT; dwFlags : DWORD; var lpCPInfoEx: TCPInfoEx): BOOL; stdcall; function GetCPInfoEx; external kernel32 name 'GetCPInfoExA'; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Check; var v_CPInfoEx : TCPInfoEx; v_CD : Cardinal; v_CharsetInfo : TCharSetInfo; v_CSN, v_CodePageName, v_s, v_info : String; v_i : Integer; begin If GetCPInfoEx(CP_ACP, 0, v_CPInfoEx) then begin v_info := 'CodePage: '+IntToStr(v_CPInfoEx.CodePage)+#13; v_CodePageName := ''; v_i := 0; repeat v_CodePageName := v_CodePageName + v_CPInfoEx.CodePageName[v_i]; inc(v_i); until v_CPInfoEx.CodePageName[v_i] = #0; v_info := v_info + 'CodePageName: '+v_CodePageName+#10#13; v_info := v_info + 'MaxCharSize: '+IntToStr(v_CPInfoEx.MaxCharSize)+' bytes.'+#13; v_s := ''; for v_i := 0 to MAX_DEFAULTCHAR - 1 do v_s := v_s + IntToStr(v_CPInfoEx.DefaultChar[v_i])+' '; v_info := v_info + 'DefaultChar: '+v_s+#13; v_s := ''; for v_i := 0 to MAX_LEADBYTES - 1 - 1 do v_s := v_s + IntToStr(v_CPInfoEx.LeadByte[v_i])+' '; v_info := v_info + 'LeadByte: '+v_s+#13; v_info := v_info + 'UnicodeDefaultChar: '+v_CPInfoEx.UnicodeDefaultChar; ShowMessage(v_info); end; end; procedure TForm1.FormShow(Sender: TObject); begin Check; end; end. 格式。

5 个答案:

答案 0 :(得分:2)

只需点击一下字符串解析

就可以做到这一点
var date   = "2016-01-06T00:00:00+05:30";

var split  = date.split('T').shift();   // 2016-01-06

var parts  = split.split('-');          // [2016, 01, 06]

var parsed = parts.reverse().join('-'); // 06-01-2016

假设日期是一个字符串,如已发布,不是日期对象,而不是来自支持$.format格式的日期选择器

答案 1 :(得分:1)

试试这个例子

document.write($.format.date("2009-12-18 10:54:50.546", "Test: dd/MM/yyyy"));

 //output Test: 18/12/2009

答案 2 :(得分:1)

在JavaScript中试试..

var fullDate = new Date();

//convert month to 2 digits
var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);
var currentDate = fullDate.getDate() + "-" + twoDigitMonth + "-" + fullDate.getFullYear();

你可以refer this article进一步..

答案 3 :(得分:0)

使用moment.js 这个功能

function ParseDate(day) {
  var value = new Date(
    parseInt(day.replace(/(^.*\()|([+-].*$)/g, ''))
  );

  var dat;
  if (value.getDate() < 10) {
    var dat =
      value.getFullYear() + "/" + (parseFloat(value.getMonth()) + 1) + "/" + "0" + value.getDate();
  } else {
    var dat = value.getFullYear() + "/" + (parseFloat(value.getMonth()) + 1) + "/" + value.getDate();
  }
  return dat;
}

答案 4 :(得分:0)

试试这个:

var date = new Date("2016-01-06T00:00:00+05:30");
day = ("0" + date.getDate()).slice(-2)
m = date.getMonth()+1;
month = ("0" + m).slice(-2)
yr = date.getFullYear();
var formatted = day+"-"+month+"-"+yr;

DEMO