1

How to convert milliseconds to date time without import library?

It's my code use date.js library

<script>
    function convertDate(mili) {
        return (new Date(mili)).toString('yyyy-MM-dd ( HH:mm:ss )');
    }
</script>

convertDate(1515395248000) => 2018-01-08 ( 14:07:28 )
yivi
  • 23,845
  • 12
  • 64
  • 89
nguyenhuyenag
  • 283
  • 4
  • 12
  • So you want to convert to a date format without using datejs or any other library? – gurvinder372 Jan 08 '18 at 08:42
  • Yes, I want without using library. – nguyenhuyenag Jan 08 '18 at 08:45
  • To get a date object it's simply `new Date(1515395248000)`, however, to get the desired format you'll have to manually create the string yourself using the in built date methods to get the right values and then concatenate. Have a look here -> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date for help on the date methods – Mark Walters Jan 08 '18 at 08:47
  • Thanks you so much. :D – nguyenhuyenag Jan 08 '18 at 08:56

0 Answers0