-4

I have tried to convert my time and date from 06/15/2017 02:45 PM to Monday, June 6, 2017 02:45 PM Is there a way to go about this?

This is what i tried:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="">

<p>Date = {{ "06/15/2017T02:45Z" | date : "EEEE, MMMM d, y h:mm a" }}</p>

</div>

<p>The date can be a date object, milliseconds, or, like in this example, a datetime string.</p>

</body>
</html>

it works only when i try:

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="">

<p>Date = {{ "06/15/2017T02:45Z" | date : "EEEE, MMMM d, y h:mm a" }}</p>

</div>

<p>The date can be a date object, milliseconds, or, like in this example, a datetime string.</p>

</body>
</html>
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106

1 Answers1

0

Working demo: https://jsfiddle.net/ddj1weez/3/

You can use a switch case statement to compare the first part of the month and then just append the rest on the date to it:

switch(month){
    case "01":
    month_written = "Jan";
    break;
  case "02":
    month_written = "Feb";
    break;
  case "03":
    month_written = "Mar";
    break;
  case "04":
    month_written = "Apr";
    break;
  case "05":
    month_written = "May";
    break;
  case "06":
    month_written = "Jun";
    break;
  case "07":
    month_written = "Jul";
    break;
  case "08":
    month_written = "Aug";
    break;
  case "09":
    month_written = "Sep";
    break;
  case "10":
    month_written = "Oct";
    break;
  case "11":
    month_written = "Nov";
    break;
  case "12":
    month_written = "Dec";
    break;
}

But as one of the comments said, you should consider implementing a JS library. https://momentjs.com/

Brian Moreno
  • 977
  • 4
  • 11
  • 39
  • Nice, this really worked the magic, but how do i add the day like monday? – Harryson Daniels Jun 12 '17 at 20:31
  • Didn't add that part, but I'll leave that up to you. A bit of help: you can use this answer (https://stackoverflow.com/a/17964363/3422027) to add that last part to the date. Hope this helps you out! :) – Brian Moreno Jun 13 '17 at 00:36