ZEOS

Địa chỉ IP của bạn: 3.143.17.128
Độ phân giải màn hình:x

Website đã chạy được 1481 ngày

Thiện - Công Nghệ Thông Tin

Trang web chia sẻ kinh nghiệm đọc, học tập, làm việc và giảng dạy của bản thân nhằm giúp mọi người có duyên ghé thăm thì có tư liệu để học tập, nghiên cứu.
Site Map Contacts Home
Hide ad unit

ĐĂNG KÝ/ĐĂNG NHẬP

QUẢNG CÁO

Advertising

BÌNH CHỌN

Bạn thích Hệ thống quản lý nội dung hay CMS (Content Management System) nào

Các khảo sát khác...

QUẢNG CÁO

Advertising

THẺ

QUẢNG CÁO

Advertising

THỐNG KÊ

{siteinfo} {prostats} {online}
{referer}
ThienCNTT » Lập trình Javascript - NodeJS » Hàm Javascript chuyển mili giây thành giờ phút giây
AuthorAuthor: admin | DateDate: 30-07-2021, 14:32

Lý thuyết: 1 mili giây = 0.001 giây -> 1,000 mili giây = 1 giây

Hàm 1: Chuyển từ 1,000 mili giây -> 00:00:01


function msToTime(duration) {
  var milliseconds = Math.floor((duration % 1000) / 100),
    seconds = Math.floor((duration / 1000) % 60),
    minutes = Math.floor((duration / (1000 * 60)) % 60),
    hours = Math.floor((duration / (1000 * 60 * 60)) % 24);

  hours = (hours < 10) ? "0" + hours : hours;
  minutes = (minutes < 10) ? "0" + minutes : minutes;
  seconds = (seconds < 10) ? "0" + seconds : seconds;

  return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
console.log(msToTime(300000))

Hàm 2: Hàm chuyển từ 1,000 mili giây -> 00:00:01


function msToTime(ms) {
  let seconds = (ms / 1000).toFixed(1);
  let minutes = (ms / (1000 * 60)).toFixed(1);
  let hours = (ms / (1000 * 60 * 60)).toFixed(1);
  let days = (ms / (1000 * 60 * 60 * 24)).toFixed(1);
  if (seconds < 60) return seconds + " Sec";
  else if (minutes < 60) return minutes + " Min";
  else if (hours < 24) return hours + " Hrs";
  else return days + " Days"
}

console.log(msToTime(1000))
console.log(msToTime(10000))
console.log(msToTime(300000))
console.log(msToTime(3600000))
console.log(msToTime(86400000))


Dear visitor, you went to the site as unregistered user. We encourage you to register or enter the site under your name.

Thêm bình luận

Name:*
E-Mail:*
Security Code
Enter Code:*
Nhấp vào hình ảnh để cập nhật mã nếu bạn không đọc được.
 


️️ 🍂️️ 💝 ️️ 🌟