I have a date formatted as 2018-06-13T13:28:14+0000, and I want to change it into this format 13/6/2018 1:28:14 PM.
Any suggestions will be helpful.
Thanks, in advance :)
I have a date formatted as 2018-06-13T13:28:14+0000, and I want to change it into this format 13/6/2018 1:28:14 PM.
Any suggestions will be helpful.
Thanks, in advance :)
Your date 2018-06-13T13:28:14+0000 is in UTC format.
One of the simplest options is to use momentjs to get desired date time format.
moment(yourDate).utc().format("DD/MM/YYYY hh:mm:ss a")
Below is code:
let date = moment("2018-06-13T13:28:14+0000").utc().format("DD/MM/YYYY hh:mm:ss a")
console.log(date)<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script> 
    
     
    
    the toLocaleString() function with the en-USlocale is close to what you are searching for. Would this be enough for you ? It will give you back something like : 
today.toLocaleString("en-US");
// will give you => 6/15/2018, 9:03:58 AM
If you really need no comma, then use the toLocaleString() and then remove the comma like :
today.toLocaleString("en-US").replace(',','');
see : https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Date/toLocaleString
 
    
    To format a Date in javascript you can use Date.toLocaleDateString() method, it will give you many options to format dates.
This is a sample code snippet, you could use:
var d = new Date();
var options = {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  hour: 'numeric',
  minute: 'numeric',
  second: 'numeric',
  hour12: true
};
console.log(d.toLocaleDateString('fr-FR', options));Note:
Of course , you can play with options to get more possible results, you can check that in the Docs as well.
Otherwise, as suggested, you can use a JS library like Moment.js or date-format, they have better enhanced features.
