Phương thức getUTCMilliseconds() trả về mili-giây (0-999) của đối tượng Date theo thời gian UTC.
Cú pháp
dateObj.getUTCMilliseconds()
- Trả về: Số nguyên 0-999
- Không nhận tham số
Ví dụ cơ bản
const date = new Date('1989-09-26T12:04:25.096Z');
console.log(date.getUTCMilliseconds()); // 96
Thiếu mili-giây
const date = new Date('1989-09-26T12:04:25Z');
console.log(date.getUTCMilliseconds()); // 0 (mặc định)
Ngày hiện tại UTC
const now = new Date();
console.log(now.getUTCMilliseconds()); // Mili-giây UTC hiện tại
Vượt phạm vi - Normalization
const date = new Date('1989-09-26T04:50:12.1035Z'); // 1035ms
console.log(date.getUTCMilliseconds()); // 35 (1035 % 1000)
console.log(date.getUTCSeconds()); // 13 (12 + 1)
Ứng dụng
- Timestamp độ chính xác cao UTC: logging, tracing, monitoring
- Performance measurement (kết hợp
performance.now()) - Distributed systems: event ordering với độ chính xác ms
- Financial trading: timestamp giao dịch
Lưu ý
- Phạm vi: 0-999
- Khác với
getMilliseconds()(local) - Vượt phạm vi auto-normalize
- Độ chính xác thực tế ~1ms (browser), tốt hơn trong Node.js
- Dùng
performance.now()cho sub-ms accuracy - Trả về
NaNnếu Date invalid - Cặp đôi với
setUTCMilliseconds()