digitalmars.D.learn - Get current date and time with std.datetime
- Joel Christensen (8/8) Oct 06 2011 Hi,
- Jonathan M Davis (2/11) Oct 06 2011 http://d-programming-language.org/intro-to-datetime.html
- Jacob Carlborg (5/16) Oct 06 2011 May I suggest that you put an example on top of that article that gets
- Jonathan M Davis (4/20) Oct 06 2011 It's already in the documentation at the top of the module. What I need ...
- Jonathan M Davis (6/27) Oct 06 2011 I just added a link to the article to std.datetime, so it'll be there st...
- Jacob Carlborg (4/31) Oct 07 2011 That would be nice too.
- Joel Christensen (8/9) Oct 06 2011 Thanks Jonathan, that helped I think, (haven't read it all, though). But...
- Jonathan M Davis (6/16) Oct 24 2011 Month is an enum. So, any function taking a month must take an enum valu...
- Luke Picardo (6/25) Jun 30 2016 Why is it so hard to simply get the current date and time
Hi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime(); -JoelCNZ
Oct 06 2011
On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:Hi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime();http://d-programming-language.org/intro-to-datetime.html
Oct 06 2011
On 2011-10-07 08:15, Jonathan M Davis wrote:On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:May I suggest that you put an example on top of that article that gets the current date and time. -- /Jacob CarlborgHi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime();http://d-programming-language.org/intro-to-datetime.html
Oct 06 2011
On Friday, October 07, 2011 08:23:10 Jacob Carlborg wrote:On 2011-10-07 08:15, Jonathan M Davis wrote:It's already in the documentation at the top of the module. What I need to do is put a link to the article in that documetantion. - Jonathan M DavisOn Friday, October 07, 2011 19:08:33 Joel Christensen wrote:May I suggest that you put an example on top of that article that gets the current date and time.Hi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime();http://d-programming-language.org/intro-to-datetime.html
Oct 06 2011
On Thursday, October 06, 2011 23:31:26 Jonathan M Davis wrote:On Friday, October 07, 2011 08:23:10 Jacob Carlborg wrote:I just added a link to the article to std.datetime, so it'll be there starting with the next release. What I'd _really_ like to see fixed though is the anchor-generation with ddoc so that I can actually properly organize the links at the top of std.datetime. - Jonathan M DavisOn 2011-10-07 08:15, Jonathan M Davis wrote:It's already in the documentation at the top of the module. What I need to do is put a link to the article in that documetantion.On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:May I suggest that you put an example on top of that article that gets the current date and time.Hi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime();http://d-programming-language.org/intro-to-datetime.html
Oct 06 2011
On 2011-10-07 08:54, Jonathan M Davis wrote:On Thursday, October 06, 2011 23:31:26 Jonathan M Davis wrote:That would be nice too. -- /Jacob CarlborgOn Friday, October 07, 2011 08:23:10 Jacob Carlborg wrote:I just added a link to the article to std.datetime, so it'll be there starting with the next release. What I'd _really_ like to see fixed though is the anchor-generation with ddoc so that I can actually properly organize the links at the top of std.datetime. - Jonathan M DavisOn 2011-10-07 08:15, Jonathan M Davis wrote:It's already in the documentation at the top of the module. What I need to do is put a link to the article in that documetantion.On Friday, October 07, 2011 19:08:33 Joel Christensen wrote:May I suggest that you put an example on top of that article that gets the current date and time.Hi, I have a program that uses the old time stuff before the module std.datetime. I have a DateTime object, but I can't seem to set its properties to the current time. Some thing like: DateTime dateTime; dateTime = getCurrentDateTime();http://d-programming-language.org/intro-to-datetime.html
Oct 07 2011
http://d-programming-language.org/intro-to-datetime.htmlThanks Jonathan, that helped I think, (haven't read it all, though). But I've got errors with some of the date times not being able to change them with int's values. task.d(44): Error: function std.datetime.DateTime.month () const is not callable using argument types (int) task.d(44): Error: cannot implicitly convert expression (month0) of type int to Month -JoelCNZ
Oct 06 2011
On Friday, October 07, 2011 19:58:12 Joel Christensen wrote:Month is an enum. So, any function taking a month must take an enum value, not an integer. e.g. Month.jan, Month.feb, Month.mar, etc. If you want to pass it an integral value, you have to cast. e.g. cast(Month)1, cast(Month)2, cast(Month)3, etc. - Jonathan M Davishttp://d-programming-language.org/intro-to-datetime.htmlThanks Jonathan, that helped I think, (haven't read it all, though). But I've got errors with some of the date times not being able to change them with int's values. task.d(44): Error: function std.datetime.DateTime.month () const is not callable using argument types (int) task.d(44): Error: cannot implicitly convert expression (month0) of type int to Month
Oct 24 2011
On Monday, 24 October 2011 at 15:29:41 UTC, Jonathan M Davis wrote:On Friday, October 07, 2011 19:58:12 Joel Christensen wrote:Why is it so hard to simply get the current date and time formatted properly in a string? There are no examples of this in your documentation yet this is probably one of the most used cases.Month is an enum. So, any function taking a month must take an enum value, not an integer. e.g. Month.jan, Month.feb, Month.mar, etc. If you want to pass it an integral value, you have to cast. e.g. cast(Month)1, cast(Month)2, cast(Month)3, etc. - Jonathan M Davishttp://d-programming-language.org/intro-to-datetime.htmlThanks Jonathan, that helped I think, (haven't read it all, though). But I've got errors with some of the date times not being able to change them with int's values. task.d(44): Error: function std.datetime.DateTime.month () const is not callable using argument types (int) task.d(44): Error: cannot implicitly convert expression (month0) of type int to Month
Jun 30 2016
On Thursday, 30 June 2016 at 21:18:22 UTC, Luke Picardo wrote:Why is it so hard to simply get the current date and time formatted properly in a string? There are no examples of this in your documentation yet this is probably one of the most used cases.To get the current time, use Clock.currTime. It will return the current time as a SysTime. To print it, toString is sufficient, but if using toISOString, toISOExtString, or toSimpleString, use the corresponding fromISOString, fromISOExtString, or fromSimpleString to create a SysTime from the string. auto currentTime = Clock.currTime(); auto timeString = currentTime.toISOExtString(); auto restoredTime = SysTime.fromISOExtString(timeString);
Jul 01 2016
On Friday, 1 July 2016 at 15:28:04 UTC, Zekereth wrote:On Thursday, 30 June 2016 at 21:18:22 UTC, Luke Picardo wrote:This is what I use: auto getDateTimeString() { import std.string; import std.datetime; DateTime dateTime = cast(DateTime)Clock.currTime(); with(dateTime) { return format( "%s " // day of the week (eg. 'Saturday') "%s.%02s.%s " // date, month, year "[%s:%02s:%02s%s]", // hour:minute:second am/pm split("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[dayOfWeek], day, cast(int)month, year, hour == 0 || hour == 12 ? 12 : hour % 12, minute, second, hour <= 11 ? "am" : "pm"); } }Why is it so hard to simply get the current date and time formatted properly in a string? There are no examples of this in your documentation yet this is probably one of the most used cases.To get the current time, use Clock.currTime. It will return the current time as a SysTime. To print it, toString is sufficient, but if using toISOString, toISOExtString, or toSimpleString, use the corresponding fromISOString, fromISOExtString, or fromSimpleString to create a SysTime from the string. auto currentTime = Clock.currTime(); auto timeString = currentTime.toISOExtString(); auto restoredTime = SysTime.fromISOExtString(timeString);
Aug 22 2016