-4

How to convert the given date to format.

Input: Sun, 11 Jun 2017 14:14:37 GMT

Output: 11-06-17 DD-MM-YY

I have tried split and then the mapping of month text to month number.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • Is this what you are looking for? [https://stackoverflow.com/questions/13459866/javascript-change-date-into-format-of-dd-mm-yyyy](https://stackoverflow.com/questions/13459866/javascript-change-date-into-format-of-dd-mm-yyyy) – Marshall Jul 12 '17 at 11:55
  • If you really want help show what you actually tried. We have no idea what you did with `split` – charlietfl Jul 12 '17 at 11:56
  • Strange that you want that output. You want `11-06-17` only, or with a literal `DD-MM-YY` following it, without time indication? – trincot Jul 12 '17 at 11:59
  • 11-06-17 only.. – Vivek Nuna Jul 12 '17 at 11:59
  • var date = new Date(" Sun, 11 Jun 2017 14:14:37 GMT"); var output=myDate.getDate() + "-"+myDate.getMonth() +"-" + myDate.getFullYear(); or date.toLocaleTimeString("en-us");//this will giv you 11/01/2017 or var options = { //change options as per your requirement i really don't know how to specify separator SORRy weekday: "long", year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" }; date.toLocaleTimeString("en-us", options)); – Pratik Thube Jul 12 '17 at 12:17

1 Answers1

1

You can do it like this:

var input = "Sun, 11 Jun 2017 14:14:37 GMT";
console.log(new Date(input).toJSON().replace(/^.*(\d\d)-(\d\d)-(\d\d).*$/, '$3-$2-$1'));
trincot
  • 317,000
  • 35
  • 244
  • 286