How can I print the actual date ? |
Post Reply |
Author | |
JulioFilho
Contributor Joined: 31.Jul.2013 Location: The Hague Points: 11 |
Post Options
Thanks(0)
Posted: 11.Mar.2014 at 14:09 |
Hi guys,
I want to include a comment line in my code with the date and time of the generation. How can I do that? Thanks in advance, Julio |
|
stevek
MetaCase Joined: 11.Mar.2008 Points: 641 |
Answer Post Options Thanks(0) |
In 5.5 and later, the code can be simpler (and significantly faster) with external...read: external 'echo %date% %time%' This will be in your current locale format. For other date formats, see https://stackoverflow.com/a/19799236/1166064. |
|
stevek
MetaCase Joined: 11.Mar.2008 Points: 641 |
Post Options
Thanks(1)
|
Date and time calculation and formatting is something we've deliberately left out of MERL, so you can just use whatever date and time library or OS function you're already familiar with. E.g. to grab the current date and time from DOS into a variable in MERL: $dateTimeFile = 'datetime.txt' external 'cmd /x /c echo %date% %time% >' $dateTimeFile executeBlocking $dateTime = __(filename $dateTimeFile read) There are probably good reasons in your case why you want to do this. In general, I wouldn't recommend including timestamps in source code - it means that every generation gives a different result, even though the real source, the model, hasn't changed. It also changes what the compiler sees as the source, so it will have to recompile every file every time; if you don't add the timestamp, MetaEdit+ automatically notices when the generated file is the same as what is already on disk, and doesn't overwrite it, which allows most compilers to avoid recompiling that file. |
|
JulioFilho
Contributor Joined: 31.Jul.2013 Location: The Hague Points: 11 |
Post Options
Thanks(0)
|
Many thanks for the quick answer.
Well, I am doing that for documentation purposes in a file that does not affect compiler or things in the sort. I do need that because I want to keep track of when the code (documentation) was generated. Though I do not agree that it is not desirable to have that in MERL, I think your answer will do the trick for the moment. Thanks again, Julio |
|
stevek
MetaCase Joined: 11.Mar.2008 Points: 641 |
Answer Post Options Thanks(0) |
In 5.5 and later, the code can be simpler (and significantly faster) with external...read: external 'echo %date% %time%' This will be in your current locale format. For other date formats, see https://stackoverflow.com/a/19799236/1166064. |
|
Post Reply | |
Tweet |
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |