Is there a difference in the usability of the date and time classes in each language? There was a topic called, and I tried to move it roughly, so I made a note. My feeling is that the date and time class is basically a recognition that represents a certain time (point). (Recognized that when initialized at '2020 / 8/21 23:59', it does not refer to the entire 59 minutes, but roughly indicates 0 seconds)
Ruby
# https://docs.ruby-lang.org/ja/latest/class/Time.html
st_t = Time.new(2020,8,21,23,59)
p st_t
check_t = Time.new(2020,8,21,23,59,30)
p (st_t < check_t)
2020-08-21 23:59:00 +0900
true
JavaScript
/*
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Date
*/
//Month is 0 base point
const st_t = new Date(2020, 8-1, 21, 23, 59);
console.log(st_t.toLocaleString("ja"));
const check_t = new Date(2020, 8-1, 21, 23, 59, 30);
console.log(
2020/8/21 23:59:00
true
PHP
<?php
# https://www.php.net/manual/ja/class.datetime.php
$st_t = new DateTime('2020-08-21T23:59');
echo $st_t->format('Y-m-d H:i:s.u');
echo "\n";
$check_t = new DateTime('2020-08-21T23:59:30');
echo $check_t->format('Y-m-d H:i:s.u');
echo "\n";
$res = ($st_t < $check_t);
if ($res){
echo "true";
}
else{
echo "false";
}
echo "\n";
2020-08-21 23:59:00.000000
2020-08-21 23:59:30.000000
true
All as expected.
Recommended Posts