Actually, today's lecture consists of two questions:
- How to get system time and date?
- How to set system time and date?
So, the first section is:
How to get system time and date?
Actually, this is not difficult task! Use the following functions:
- Now - function returns the current date and time according to the setting of your computer's system date and time.
- Date - function returns the current system date.
- Time - function returns a Variant of subtype Date indicating the current system time.
Well, let's deal with the second section:
How to set system time and date?
For that, I will use simple DOS commands:
- time - this command displays or sets the system time:
To change the time, pass it as a parameter to time command. See the above screen shot as an example. - date - this command displays or sets the system date:
To change the date, pass it as a parameter to date command. See the above screen shot as an example for date manipulations :)
As you can see, initial date and time were '26.10.2007 22:45:10'. Then I added 3 days and 2 hours to initial date & time. The result of addition is - '30.10.2007 0:45:10'.
By the way, could you guess, why the result day is 30th, not 29th? :) To answer, please pay attention that we added 2 hours too :)
The last step - running of time and date commands from command line. I used Run method of WScript.Shell object.
So, as you can see - date and time manipulation is easy enough.
Source
0 comments:
Post a Comment