Day.js is a JavaScript library that lets us manipulate dates in our apps.
In this article, we’ll look at how to use Day.js to manipulate dates in our JavaScript apps.
Set the Number of Milliseconds of a Date
To set the number of milliseconds in a Day.js date we can use the millisecond
method:
const dayjs = require("dayjs");
const result = dayjs().millisecond(1);
console.log(result);
We set the number of milliseconds of the date to 1 with 1 as the argument of milliseconds
.
Set the Number of Seconds of a Date
To set the number of seconds in a Day.js date we can use the millisecond
method:
const dayjs = require("dayjs");
const result = dayjs().second(1);
console.log(result);
We set the number of seconds of the date to 1 with 1 as the argument of second
.
Set the Number of Minutes of a Date
To set the number of minutes in a Day.js date we can use the minute
method:
const dayjs = require("dayjs");
const result = dayjs().minute(1);
console.log(result);
We set the number of minutes of the date to 1 with 1 as the argument of minute
. Minutes range from 0 to 59.
Set the Number of Hours of a Date
To set the number of hours in a Day.js date we can use the hours
method:
const dayjs = require("dayjs");
const result = dayjs().hour(1);
console.log(result);
We set the number of hours of the date to 1 with 1 as the argument of hour
.
Conclusion
Day.js is a JavaScript library that lets us manipulate dates in our apps.