Home >Web Front-end >JS Tutorial >Introduction to some usage of JavaScript date type_javascript skills
Get the number of days in a certain month
I believe that when you were in primary school, you all knew how many days there are in each of the twelve months of the year. There is a special existence in it - February. February in leap years has 29 days, while February in non-leap years has only 28 days. It is estimated that many people, like me, have forgotten the rules of leap years. At this time, the following method comes in handy.
Similarly, we can also use this method to determine whether a certain year is a leap year:
The getTimezoneOffset() method of date type can get the time difference between Greenwich time and local time, in minutes. For example:
Besides this, there is another way. After calling toString() of the date type, you can get a date string in a fixed format:
Calculate running time
How to measure the execution time of a certain program? The method is very simple. Record the time before execution. After execution, subtract the time before execution from the current time to get the result:
Delete cookies
To be precise, we cannot delete cookies directly through Javascript. The only way to erase a cookie from the world is to let it expire, so that the browser's built-in mechanism will automatically kill it.
The most straightforward way to make a cookie expire is to set its expiration time to the minimum value. The smallest date that can be expressed in Javascript is 0:00:00 on January 1, 1970. You can create such a date object through new Date(0):