Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c298f9e

Browse files
Merge pull request avinashkranjan#254 from vaishnavijha/master
script to run program at a given time
2 parents 1ae1417 + e44e021 commit c298f9e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hii guys ,your Lunch time begins !
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import datetime library in python
2+
from datetime import datetime
3+
# Saves a .txt file with file name
4+
# as 2020年01月11日-10-20-23.txt at current time indicated by now function of datetime library
5+
with open(datetime.now().strftime("%Y-%m-%d-%H-%M-%S"), "w")as myfile:
6+
#instead of now i could also initialse with datetime(1999, 12, 12, 12, 12, 12, 342380) to give the time values to datetime constructor
7+
# Content of the file (it can be any script in python which we want to run at a particular time )
8+
myfile.write("hii guys ,your Lunch time begins ! ")
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# DateTime
2+
3+
The datetime module supplies classes for manipulating dates and times.
4+
for ex: to Import the datetime module and display the current date:
5+
6+
import datetime
7+
x = datetime.datetime.now()
8+
print(x)
9+
When we execute the code from the example above the result will be:
10+
11+
2021年01月14日 23:14:32.037299
12+
The date contains year, month, day, hour, minute, second, and microsecond.
13+
14+
method for saving it as a different file once code is executed:
15+
The datetime object has a method for formatting date objects into readable strings.
16+
The method is called strftime(), and takes one parameter, format, to specify the format of the returned string:
17+
18+
## Setup instructions
19+
20+
actually we have used datetime library of python so if its not installed previously please run command pip install DateTime in terminal
21+
Now simply run the code and set the output in the newly formed file with the name as current date .
22+
23+
## Output
24+
25+
the output file is formed with the name of current date and time and the content of file as per script of code.
26+
27+
## Author(s)
28+
29+
vaishnavi jha

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /