GetMonth() - month from 0 to 11 (countdown starts from zero) By the way, you should use the getFullYear() method instead of getYear(), because the latter returns two digits only. This group of methods deserve a bit more attention: setHours( 12, 12, 12, 12) // specify only hours, minutes, seconds, milliseconds Date.prototype Get methods In this case, if a component is not specified, it does not change. As you see, some methods can set multiple date components at once. Indicated in square brackets are optional parameters. The following methods from the Set group allow you to set the date and time components comprehensively or individually to change one value: These groups of methods include ways to access the various components of the date and time of the Date object together or separately. Among the Date methods we can distinguish two groups such as Set and Get methods. It is impossible to create time in hours only, it must be dated (year, month, day). It is easy to guess that it returns the actual time. The most useful method in practice is Data.now(). If it will be difficult to correct the date, the method will still cope with it. The logic of the Date is thought out to the smallest detail - even if you specify incorrect values for a field, the Date constructor will automatically convert them to the correct ones (though the date can be significantly changed).įor example, if specifying the number of minutes you specify 100 (while the maximum number of minutes is 59), the constructor will add one hour to the field with hours, and the value 41 will remain in minutes (100-59). New Date(year, month, day, hour, minute, second, millisecond) Okay, syntax of data object looks as follows: new Date() //will create an object with the current date and time new Date(value) Date objects can be used to store, create, change, measure time or display the current date. In addition to the fact that you can work with the Date object itself, it contains methods that can deal with dates too. In JavaScript, the date object works with everything related to date and time. Of course, programmers often have to work with dates and there are several things and expressions in JS designed to save time and effort, as well as make code volume lower. Certain functions or expressions prepared in advance, for instance, such mathematical constants as epsilon or Pi have already been initialized, functions to convert variables or to get their values are in place, and so on. In every programming language there are tips, tricks and shortcuts to decrease effort when coding and increase work efficacy. Operators: Addition assignment operator (+=).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |