ฟังก์ชั่นสำหรับแปลง timestamp ให้เป็นเวลาที่มนุษย์เข้าใน JavaScript

const showTime = (value) => {
    let unix_timestamp = value;
    let date = new Date(unix_timestamp);
    let hours = date.getHours();
    let minutes = date.getMinutes();
    if(hours<10) hours = "0"+ hours;
    if(minutes<10) minutes = "0"+ minutes;
    return hours+':'+minutes;
  }
  const now = new Date().getTime();
  console.log(showTime(now));

Leave a comment

Your email address will not be published. Required fields are marked *