Milliseconds with wxDateTime/wxLogFormatter?

395 views
Skip to first unread message

Tobias Abt

unread,
Feb 26, 2015, 4:32:44 AM2/26/15
to wx-u...@googlegroups.com

Hi *,

 

I’m trying to add milliseconds to my log-output:

 

wxString MyLogFormatter::FormatTime (time_t time) const

{

     return wxDateTime(time).Format("%Y.%m.%d-%H:%M:%S.%l");

}

 

But all I get for milliseconds is “000”…

 

What should I do get milliseconds?

 

 

Regards and thanks for your help,

Tobi

 

Marian 'VooDooMan' Meravy

unread,
Feb 26, 2015, 5:35:57 AM2/26/15
to wx-u...@googlegroups.com
Greetings,

On 2015-02-26 10:32, Tobias Abt wrote:
> Hi *,
>
>
> I’m trying to add milliseconds to my log-output:
>
>
> wxString MyLogFormatter::FormatTime (time_t time) const
>
> {
>
> return wxDateTime(time).Format("%Y.%m.%d-%H:%M:%S.%l");
>
> }

"time_t" is just unsigned int i.e. "count of seconds", there are no
miliseconds. You need few other calls to get mili's.

Take a look here: http://docs.wxwidgets.org/trunk/classwx_date_time.html

e.g. constructor:

wxDateTime (wxDateTime_t hour, wxDateTime_t minute=0, wxDateTime_t
second=0, wxDateTime_t millisec=0)

or Set() methods...

best,
vdm
.

signature.asc

Marian 'VooDooMan' Meravy

unread,
Feb 26, 2015, 6:02:13 AM2/26/15
to wx-u...@googlegroups.com
Greetings,
perhaps you should give a try to this one:

http://docs.wxwidgets.org/trunk/classwx_date_time.html#a0db1c9bac7b2d27d589cad2a38d1438c

( "UNow()" static function )

see example for "Now()" to see how to use it:
http://docs.wxwidgets.org/trunk/classwx_date_time.html#a6e6c37a0414bb4831e2cc03b37f498a2

best,
vdm
.

signature.asc

Tobias Abt

unread,
Feb 27, 2015, 9:19:50 AM2/27/15
to wx-u...@googlegroups.com
Hi,
Thanks for your reply.
On my machine time_t looked bigger ;)

So from what I gathered it is not possible to add (the correct) milliseconds to the timestamp:
The time is set in the constructor of wxLogRecordInfo and if 'time_t' does not provide the necessary accuracy, it makes little sense to add a different time later.
Well, it would do for the main-thread, but as soon as another thread starts logging, the time is completely wrong (about 1s on my machine).

Or am I missing something?

Regards,
Tobi

Windows 7 with wxWidgets 3.0.2 and VS2010



>> -----Ursprüngliche Nachricht-----
>> Von: wx-u...@googlegroups.com [mailto:wx-u...@googlegroups.com]
>> Im Auftrag von Marian 'VooDooMan' Meravy
>> Gesendet: Donnerstag, 26. Februar 2015 12:02
>> An: wx-u...@googlegroups.com
>> Betreff: [MASSMAIL]Re: Milliseconds with wxDateTime/wxLogFormatter?
>> --
>> Please read http://www.wxwidgets.org/support/mlhowto.htm before
>> posting.
>>
>> To unsubscribe, send email to wx-users+u...@googlegroups.com
>> or visit http://groups.google.com/group/wx-users

Vadim Zeitlin

unread,
Feb 27, 2015, 10:19:35 AM2/27/15
to wx-u...@googlegroups.com
On Fri, 27 Feb 2015 15:19:45 +0100 Tobias Abt wrote:

TA> So from what I gathered it is not possible to add (the correct)
TA> milliseconds to the timestamp: The time is set in the constructor of
TA> wxLogRecordInfo and if 'time_t' does not provide the necessary
TA> accuracy, it makes little sense to add a different time later. Well, it
TA> would do for the main-thread, but as soon as another thread starts
TA> logging, the time is completely wrong (about 1s on my machine).
TA>
TA> Or am I missing something?

wxLog functions only use time_t, but you also have a possibility to
associate arbitrary values in the log records, so you could use this to
store a higher precision timestamp in addition to time_t. It won't be as
seamless as just using time_t but should definitely work.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Reply all
Reply to author
Forward
0 new messages