0

The given time is in a format of ISO_8601 E.g: "2019-04-05T13:30-05:00" E.g: "2005-08-09T18:31+03:30" should return an exact time in a readable format with the GMT which is mentioned E.g. Sat, Nov 30, 2019, 11:00 PM GMT+1

Input: "2019-04-05T13:30-05:00" Output: "FRI, APR 5, 2019, 1:30 PM GMT-5"

Input: "2005-08-09T18:31+03:30" Output: "TUE, AUG 9, 2005, 6:31 PM GMT+3"

user116313
  • 25
  • 3
  • The second example GMT+3? isn't it supposed to be GMT+3:30? – Ali Elkhateeb Nov 08 '19 at 20:04
  • @Ali Yes. I believe you are right it should be "GMT+3:30" – user116313 Nov 08 '19 at 20:19
  • 1
    There are already many questions and good answers on [*how to format a date*](https://stackoverflow.com/search?q=%5Bjavascript%5D+how+to+format+a+date). Try something, and if you have issues, post the code and ask for help rather than just asking for someone to write the code for you. – RobG Nov 08 '19 at 22:09
  • @user116313—For what value of "should"? ISO 8601 allows +3, +0300 or +03:00. [*ECMAScript*](http://ecma-international.org/ecma-262/10.0/#sec-date-time-string-format) requires +03:00. So +3:00 is the only format **not** supported by either ISO 8601 or ECMA-262. – RobG Nov 08 '19 at 22:19

1 Answers1

-1

I suggest you use Momentjs, here is a simple snippet how to do it with moment.

function getDateString(inputDate) {
  let date = moment.parseZone(inputDate);

  return date.format('ddd, MMM D, YYYY, h:mm A zZ')
}

console.log(getDateString("2005-08-09T18:31+03:30"));
console.log(getDateString("2019-04-05T13:30-05:00"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
Ali Elkhateeb
  • 3,413
  • 4
  • 21
  • 39
  • Thank you, actually, this worked for me `code`getTime (inputDate) { const data = this.$moment.parseZone(inputDate).format('ddd, MMM D, YYYY, h:mm A [GMT]Z') return data } – user116313 Nov 11 '19 at 11:13