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
  • 34,719
  • 24
  • 185
  • 251
Divyesh
  • 329
  • 3
  • 16

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
  • 303,455
  • 27
  • 380
  • 377
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
  • 4,853
  • 1
  • 31
  • 34
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,268
  • 1
  • 11
  • 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,860
  • 7
  • 28
  • 53
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
  • 4,987
  • 8
  • 35
  • 89