Hướng dẫn sử dụng Castor EDC Hướng dẫn tính toán Castor EDC Các câu hỏi thường gặp Bài viết dành cho người quản lý dữ liệu Tài liệu phát hành tuân thủ Castor EDC
Hướng dẫn sử dụng Castor eConsent Tài liệu phát hành tuân thủ Castor eConsent
Hướng dẫn sử dụng SMS của Castor Tài liệu phát hành tuân thủ SMS của Castor
Tài liệu phát hành tuân thủ Castor Connect
Tin tức Tài nguyên khác
Để tính chênh lệch giữa hai trường thời gian theo giờ, phút hoặc giây, hãy sử dụng công thức sau trong đó time_variable_1 là điểm thời gian đầu tiên [trường thời gian] và time_variable_2 là điểm thời gian thứ hai. Thay thế chúng bằng tên biến của riêng bạn Bạn cũng có thể thay đổi đơn vị thời gian Vì các trường thời gian chỉ chụp giờ và phút, sự khác biệt này sẽ luôn được làm tròn đến 60 giây gần nhất Ghi chú. Công thức này chỉ hợp lệ nếu hai thời điểm vào cùng một ngày. Nếu hai thời điểm diễn ra trong hai ngày liên tiếp, bạn có thể sử dụng một trong các phép tính sau, tùy thuộc vào việc bạn muốn kết quả tính bằng giờ, phút hay cả hai. Mẫu này yêu cầu điền thời gian ở định dạng 24 giờ. Sự khác biệt này sẽ được làm tròn đến 60 giây gần nhất ví dụ 1. Ví dụ này sử dụng ngày hiện tại và ngày năm mới tiếp theo để nhận chênh lệch ngày tính bằng phút. Chênh lệch thời gian giữa hai trường thời gian trong cùng một ngày
getTimeDiff['{time_variable_2}', '{time_variable_1}', 'm'];
Chênh lệch thời gian giữa hai trường thời gian vào hai ngày liên tiếp
html
body
0body
1
body
3____9>
body
6
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
1>
2>
body
3____59>
body
6
body
0
7
body
3
1>
body
6
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
1
body
3____59>
body
6
h1
6
body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
02body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
04const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
05body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
07body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
09body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
11const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
05body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
14body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
16const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
17const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
18const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
19const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
20const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
05body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
23body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
25body
0
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
27const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
17const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
29const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
17>
1const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
17>
3body
0>
5
body
3____99>
body
3____5>
đầu ra
ví dụ 2. Ví dụ này sử dụng ngày Năm mới 2019 và Năm mới 2020 để nhận chênh lệch tính bằng phút.
Chúng tôi có thể chuyển đổi các đối tượng ngày JavaScript thành dấu thời gian, trừ chúng và sau đó chuyển đổi chênh lệch thành phút
Để làm điều này, chúng tôi viết
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
Chúng tôi có các đối tượng ngày tháng
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
07 và const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
08 mà chúng tôi muốn nhận được sự khác biệt tính bằng phút giữaỞ dòng thứ 3, chúng tôi chuyển đổi các đối tượng ngày tháng
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
07 và const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
08 thành dấu thời gian tính bằng mili giây với toán tử const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
11 ở phía trước chúngSau đó, chúng tôi chia
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
12 cho 1000 để chuyển đổi chênh lệch tính bằng giâyVà sau đó chúng tôi chia số đó cho 60 để chuyển đổi thành phút
Sau đó, từ nhật ký bảng điều khiển, chúng ta sẽ thấy số phút chênh lệch giữa
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
07 và const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
08 là 41760Chúng tôi cũng có thể chuyển đổi
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
07 và const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = +d2 - +d1;
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
08 thành dấu thời gian bằng phương pháp const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = d2.getTime[] - d1.getTime[];
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
2Chẳng hạn, chúng ta có thể viết
const d2 = new Date[2020, 2, 1];
const d1 = new Date[2020, 1, 1];
const diffMs = d2.getTime[] - d1.getTime[];
const diffMins = Math.floor[[diffMs / 1000] / 60];
console.log[diffMins]
Và chúng tôi nhận được kết quả tương tự như trước đây
Phần kết luậnChúng ta có thể lấy chênh lệch giữa 2 ngày tính bằng phút bằng cách chuyển đổi thành dấu thời gian tính bằng mili giây, trừ đi 2 dấu thời gian và chuyển đổi chênh lệch thành phút