0

I have get Date in jQuery but this 2016-01-06T00:00:00+05:30 Format, But I want to only 06-01-2016 format.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Divyesh
  • 329
  • 3
  • 17

5 Answers5

2

You can do that with just a litle bit of string parsing

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

Assuming the date is a string, as posted, not a date object, and not coming from a datepicker that supports formatting with $.format

adeneo
  • 312,895
  • 29
  • 395
  • 388
1

try this example

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

 //output Test: 18/12/2009
Maheshvirus
  • 6,749
  • 2
  • 38
  • 40
1

Try this in 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();

and you can refer this article for further..

Sarath
  • 2,318
  • 1
  • 12
  • 24
0

use moment.js and this fuction

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;
}
Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
0

Try this:

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

Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97