How do I convert the output of “getctime()” and “getmtime()” into the time format required by HTML's “published_time” and “modified_time” META tags?How do you disable browser Autocomplete on web form field / input tag?How to flush output of print function?How to get file creation & modification date/times in Python?How do I wrap text in a pre tag?What do 'real', 'user' and 'sys' mean in the output of time(1)?How do I get time of a Python program's execution?How to manage local vs production settings in Django?How do you convert epoch time in C#?“Large data” work flows using pandasFormatting the Output
Which household object drew this pattern?
Three Singles in Three Clubs
Church Booleans
How would one country purchase another?
How should I face my manager if I make a mistake because a senior coworker explained something incorrectly to me?
Solve a logarithmic equation by NSolve
How to refer to a regex group in awk regex?
Avoiding racist tropes in fantasy
Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?
LeetCode: Pascal's Triangle C#
How would a situation where rescue is impossible be handled by the crew?
Give function defaults arguments from a dictionary in Python
Is it appropriate for a prospective landlord to ask me for my credit report?
Why aren't RCS openings an issue for spacecraft heat shields?
Efficiently pathfinding many flocking enemies around obstacles
map 5 unequal ranges to id
What to say to a student who has failed?
Are required indicators necessary for radio buttons?
Is there such a thing as too inconvenient?
Brexit and backstop: would changes require unanimous approval by all EU countries? Does Ireland hold a veto?
How does turbine efficiency compare with internal combustion engines if all the turbine power is converted to mechanical energy?
Is there any practical application for performing a double Fourier transform? ...or an inverse Fourier transform on a time-domain input?
How can I watch the 17th (or last, if less) line in files of a folder?
IndexOptimize - Configuration
How do I convert the output of “getctime()” and “getmtime()” into the time format required by HTML's “published_time” and “modified_time” META tags?
How do you disable browser Autocomplete on web form field / input tag?How to flush output of print function?How to get file creation & modification date/times in Python?How do I wrap text in a pre tag?What do 'real', 'user' and 'sys' mean in the output of time(1)?How do I get time of a Python program's execution?How to manage local vs production settings in Django?How do you convert epoch time in C#?“Large data” work flows using pandasFormatting the Output
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
My website's articles are written using .md
files, to get the created and modified times of these files I use the os.path.getctime()
and os.path.getmtime()
methods.
The output of these methods look like this:
1553541590.723329
1553541590.723329
While HTML requires this format:
2001-09-17T05:59:00+01:00
2013-09-16T19:08:47+01:00
I have two questions regarding this matter:
- What's are the names of these two time formats?
- How do I change the output of those methods to look like the required HTML format?
Thanks.
python html python-3.x time time-format
add a comment |
My website's articles are written using .md
files, to get the created and modified times of these files I use the os.path.getctime()
and os.path.getmtime()
methods.
The output of these methods look like this:
1553541590.723329
1553541590.723329
While HTML requires this format:
2001-09-17T05:59:00+01:00
2013-09-16T19:08:47+01:00
I have two questions regarding this matter:
- What's are the names of these two time formats?
- How do I change the output of those methods to look like the required HTML format?
Thanks.
python html python-3.x time time-format
add a comment |
My website's articles are written using .md
files, to get the created and modified times of these files I use the os.path.getctime()
and os.path.getmtime()
methods.
The output of these methods look like this:
1553541590.723329
1553541590.723329
While HTML requires this format:
2001-09-17T05:59:00+01:00
2013-09-16T19:08:47+01:00
I have two questions regarding this matter:
- What's are the names of these two time formats?
- How do I change the output of those methods to look like the required HTML format?
Thanks.
python html python-3.x time time-format
My website's articles are written using .md
files, to get the created and modified times of these files I use the os.path.getctime()
and os.path.getmtime()
methods.
The output of these methods look like this:
1553541590.723329
1553541590.723329
While HTML requires this format:
2001-09-17T05:59:00+01:00
2013-09-16T19:08:47+01:00
I have two questions regarding this matter:
- What's are the names of these two time formats?
- How do I change the output of those methods to look like the required HTML format?
Thanks.
python html python-3.x time time-format
python html python-3.x time time-format
edited Apr 3 at 12:36
LogicalBranch
asked Mar 27 at 16:02
LogicalBranchLogicalBranch
2,3162 gold badges10 silver badges40 bronze badges
2,3162 gold badges10 silver badges40 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
1) The os.path documentation indicates that both os.path.getctime()
and os.path.getmtime()
return a float indicating seconds since epoch. That seems consistent with the numbers you are getting.
2) The easiest thing to do would be to convert to an object to represent a date and then provide your desired format. Here, I used datetime with strftime()
to output a string of desired format.
import datetime
>>>> datetime.datetime.fromtimestamp(1553541590.723329)
datetime.datetime(2019, 3, 25, 12, 19, 50, 723329)
>>>> datetime.datetime.fromtimestamp(1553541590.723329).strftime('%Y-%m-%dT%H:%M:%S')
'2019-03-25T12:19:50'
You may find it easiest to just add the time zone string on the end since adding a timezone to a datetime object is a little involved. If you do want to go through with it, you need to create a tzinfo
object and use it to update the datetime
object using datetime.astimezone(tz)
. Here's a pretty good resource for adding a timezone to a datetime object.
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
1
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
1
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381649%2fhow-do-i-convert-the-output-of-getctime-and-getmtime-into-the-time-forma%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
1) The os.path documentation indicates that both os.path.getctime()
and os.path.getmtime()
return a float indicating seconds since epoch. That seems consistent with the numbers you are getting.
2) The easiest thing to do would be to convert to an object to represent a date and then provide your desired format. Here, I used datetime with strftime()
to output a string of desired format.
import datetime
>>>> datetime.datetime.fromtimestamp(1553541590.723329)
datetime.datetime(2019, 3, 25, 12, 19, 50, 723329)
>>>> datetime.datetime.fromtimestamp(1553541590.723329).strftime('%Y-%m-%dT%H:%M:%S')
'2019-03-25T12:19:50'
You may find it easiest to just add the time zone string on the end since adding a timezone to a datetime object is a little involved. If you do want to go through with it, you need to create a tzinfo
object and use it to update the datetime
object using datetime.astimezone(tz)
. Here's a pretty good resource for adding a timezone to a datetime object.
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
1
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
1
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
add a comment |
1) The os.path documentation indicates that both os.path.getctime()
and os.path.getmtime()
return a float indicating seconds since epoch. That seems consistent with the numbers you are getting.
2) The easiest thing to do would be to convert to an object to represent a date and then provide your desired format. Here, I used datetime with strftime()
to output a string of desired format.
import datetime
>>>> datetime.datetime.fromtimestamp(1553541590.723329)
datetime.datetime(2019, 3, 25, 12, 19, 50, 723329)
>>>> datetime.datetime.fromtimestamp(1553541590.723329).strftime('%Y-%m-%dT%H:%M:%S')
'2019-03-25T12:19:50'
You may find it easiest to just add the time zone string on the end since adding a timezone to a datetime object is a little involved. If you do want to go through with it, you need to create a tzinfo
object and use it to update the datetime
object using datetime.astimezone(tz)
. Here's a pretty good resource for adding a timezone to a datetime object.
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
1
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
1
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
add a comment |
1) The os.path documentation indicates that both os.path.getctime()
and os.path.getmtime()
return a float indicating seconds since epoch. That seems consistent with the numbers you are getting.
2) The easiest thing to do would be to convert to an object to represent a date and then provide your desired format. Here, I used datetime with strftime()
to output a string of desired format.
import datetime
>>>> datetime.datetime.fromtimestamp(1553541590.723329)
datetime.datetime(2019, 3, 25, 12, 19, 50, 723329)
>>>> datetime.datetime.fromtimestamp(1553541590.723329).strftime('%Y-%m-%dT%H:%M:%S')
'2019-03-25T12:19:50'
You may find it easiest to just add the time zone string on the end since adding a timezone to a datetime object is a little involved. If you do want to go through with it, you need to create a tzinfo
object and use it to update the datetime
object using datetime.astimezone(tz)
. Here's a pretty good resource for adding a timezone to a datetime object.
1) The os.path documentation indicates that both os.path.getctime()
and os.path.getmtime()
return a float indicating seconds since epoch. That seems consistent with the numbers you are getting.
2) The easiest thing to do would be to convert to an object to represent a date and then provide your desired format. Here, I used datetime with strftime()
to output a string of desired format.
import datetime
>>>> datetime.datetime.fromtimestamp(1553541590.723329)
datetime.datetime(2019, 3, 25, 12, 19, 50, 723329)
>>>> datetime.datetime.fromtimestamp(1553541590.723329).strftime('%Y-%m-%dT%H:%M:%S')
'2019-03-25T12:19:50'
You may find it easiest to just add the time zone string on the end since adding a timezone to a datetime object is a little involved. If you do want to go through with it, you need to create a tzinfo
object and use it to update the datetime
object using datetime.astimezone(tz)
. Here's a pretty good resource for adding a timezone to a datetime object.
edited Mar 28 at 18:58
answered Mar 27 at 18:25
ASaundersASaunders
1817 bronze badges
1817 bronze badges
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
1
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
1
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
add a comment |
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
1
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
1
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
Thank you very much for taking the time and putting in the effort to answer this question, it made my day! Thanks!
– LogicalBranch
Mar 28 at 11:33
1
1
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
No problem! Good luck with your project :)
– ASaunders
Mar 28 at 18:57
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
This answer saved me a lot of trouble with my (now completed) project, I've awarded you a bounty to thank you.
– LogicalBranch
Apr 18 at 15:25
1
1
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
How nice! And congratulations on the successful project. That's always a good feeling.
– ASaunders
Apr 19 at 17:03
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55381649%2fhow-do-i-convert-the-output-of-getctime-and-getmtime-into-the-time-forma%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown