<b>Select Datetime</b><br/>
<DateTimeField onChange={this.clockevent} format={"x"}/>
clockevent=(newDate)=>{
var dateVal ="/Date("+newDate+")/";
var date = new Date(parseFloat(dateVal.substr(6)));
console.log(
date.getFullYear() + " " +
(date.getMonth() + 1) + "/" +
date.getDate() + " " +
date.getHours() + ":" +
date.getMinutes() + ":" +
date.getSeconds() );
}
result :
2018/2/1 14:16:0
i want the result add day,month and ss ' format (DD MM ss) i want to this format =
2018/02/01 14:16:00
To format a date as dd/mm/yyyy:Use the getDate() , getMonth() and getFullYear() methods to get the day, month and year of the date. Add a leading zero to the day and month digits if the value is less than 10 .
The toDateString() Method in JavaScript First three letters of the week day name. First three letters of the month name. Two digit day of the month, padded on the left a zero if necessary. Four digit year (at least), padded on the left with zeros if necessary.
I haven't found the way to format YYYY/MM/DD as you asked but I have the 2-digit format.
const today = Date.now();
console.log(new Intl.DateTimeFormat('en-US', {year: 'numeric', month: '2-digit',day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit'}).format(today));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With