Java Reference
In-Depth Information
This can be useful for incrementing dates by a set amount of time; for example, a day can
be represented by 1000 * 60 * 60 * 24 milliseconds :
> christmasEve = new Date(christmas.getTime() - 1000 * 60
* 60 * 24)
<< [object Date]{
> christmasEve.toString();
<< Fri Dec 26 2014 00:00:00 GMT+0000 (GMT)"
The getTimezoneOffset() method returns the difference, in minutes, between local
time and UTC. For example, my timezone is currently British Summer Time:
> new Date().getTimezoneOffset()
<< -60
This shows that British Summer Time is one hour ahead of UTC.
Setter Methods
Most of the getter methods covered in the previous section have equivalent setter methods .
These are methods that can be used to change the value of the date held in a Date object.
Each of the methods takes an argument representing the value to which you update the date.
The methods return the timestamp of the updated date object.
As an example, we can change the value of the date stored in the diwali variable so that
it contains the date of Diwali in 2015, which is on Wednesday, November 11, 2015:
> diwali.setDate(11);
<< 1412982000000
> diwali.setMonth(10); // November is month 10
<< 1415664000000
Search WWH ::

Custom Search