-6

How to format date returned from server in this format

2016-08-17T11:17:57+04:00 in human readable format - for example

17-08-2016, 11:17 AM

in jquery?

I've tried this solution but the problem is that its always converting the time in IST. Even people from US is also seeing this in IST. Not quite getting what is the problem.

Tried this but the problem still persists.

Changing Date Time Format using jquery/javascript

Community
  • 1
  • 1
Avishek
  • 135
  • 11
  • 5
    Possible duplicate: http://stackoverflow.com/questions/25275696/javascript-format-date-time http://jsfiddle.net/a_incarnati/kqo10jLb/4/ – Jonathan Newton Aug 18 '16 at 09:57
  • Maybe this topic will help you http://stackoverflow.com/questions/3075577/convert-mysql-datetime-stamp-into-javascripts-date-format – Ionut Necula Aug 18 '16 at 09:57
  • new Date("2016-08-17T11:17:57+04:00") - you have .toLocaleDateString and toLocaleTimeString – mplungjan Aug 18 '16 at 09:59
  • Possible duplicate of [Formatting the date time with Javascript](http://stackoverflow.com/questions/8847109/formatting-the-date-time-with-javascript) – Mike F Aug 18 '16 at 10:38

2 Answers2

0

try this Getting only selected date in bootstrap-date paginator

if you do not want the month from name, just keep the month value,not the name

more additionally, I think this is what you want to get the date try this

<!DOCTYPE html>
<html>
<head>
 <title></title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
 

 
</body>

<script type="text/javascript">
  var datestring = "2016-08-17T11:17:57+04:00";
  var mydate = new Date(datestring);
  var thedate = mydate.getDate();
  var month = mydate.getMonth();
  var year = mydate.getFullYear();
 


 
  var theresult = year +"-"+"0"+(month+1)+"-"+thedate;
  alert(theresult);

   

</script>
</html>
Community
  • 1
  • 1
caldera.sac
  • 4,918
  • 7
  • 37
  • 69
0

Version 1:

function pad(num) {
  return String("0"+num).slice(-2);
}
function formatDate(d) {
   day = d.getDate();
 month = d.getMonth()+1,
  year = d.getFullYear();
  return ""+pad(day)+"-"+pad(month)+"-"+year+" "+d.toLocaleTimeString();
}
var d = new Date("2016-08-17T11:17:57+04:00");
console.log(formatDate(d));

version 2:

function chopString(d) {
  var parts = d.split("T");
  return parts[0] + " " + parts[1].split("+")[0];
}
console.log(chopString("2016-08-17T11:17:57+04:00"));
mplungjan
  • 169,008
  • 28
  • 173
  • 236