Discussion:
CDateTimeCtrl to display UTC
(too old to reply)
A***@yahoo.com
2008-01-18 12:44:50 UTC
Permalink
Ok, the problem is this; I am using a pair of CDateTimeCtrls one for
the date and one for hours/minutes/seconds. The problem I have is that
I need to work in UTC - all my internal calculations are using time_t
and the times shown to and selected by the user must be in UTC. I'm
getting into problems as the controls adjust for local time which I
don't want. I think I need to detect if an offset from UTC is in
effect and add/subtract that ammout when setting / reading from the
controls.

This is getting a bit ugly - can anyone think of a more elegant
solution?

Regards
Allan
AliR (VC++ MVP)
2008-01-18 16:13:25 UTC
Permalink
I don't think I quite understand the problem. If the user is entering the
time, then it is what they are entering, what does that have anything to do
with the timezone?
Say the user enters 10:52am UTC
When you call GetTime on the DateTime control, it will return a time struct
with todays date, 10:52am in the time. Why would you have to convert
anything?
Maybe I don't see the entire problem. Anyway CTime has a GetGmtTm, and there
is also TzSpecificLocalTimeToSystemTime (converts local time to a UTC time)
and of course SystemTimeToTzSpecificLocalTime.


AliR.
Post by A***@yahoo.com
Ok, the problem is this; I am using a pair of CDateTimeCtrls one for
the date and one for hours/minutes/seconds. The problem I have is that
I need to work in UTC - all my internal calculations are using time_t
and the times shown to and selected by the user must be in UTC. I'm
getting into problems as the controls adjust for local time which I
don't want. I think I need to detect if an offset from UTC is in
effect and add/subtract that ammout when setting / reading from the
controls.
This is getting a bit ugly - can anyone think of a more elegant
solution?
Regards
Allan
A***@yahoo.com
2008-01-21 12:23:16 UTC
Permalink
I don't think I quite understand the problem.  If the user is entering the
time, then it is what they are entering, what does that have anything to do
with the timezone?
Say the user enters 10:52am UTC
When you call GetTime on the DateTime control, it will return a time struct
with todays date, 10:52am in the time.  Why would you have to convert
anything?
Maybe I don't see the entire problem. Anyway CTime has a GetGmtTm, and there
is also TzSpecificLocalTimeToSystemTime (converts local time to a UTC time)
and of course SystemTimeToTzSpecificLocalTime.
AliR.
Ok, the problem is this;  I am using a pair of CDateTimeCtrls one for
the date and one for hours/minutes/seconds. The problem I have is that
I need to work in UTC - all my internal calculations are using time_t
and the times shown to and selected by the user must be in UTC.  I'm
getting into problems as the controls adjust for local time which I
don't want.  I think I need to detect if an offset from UTC is in
effect and add/subtract that ammout when setting / reading from the
controls.
This is getting a bit ugly - can anyone think of a more elegant
solution?
Regards
  Allan- Hide quoted text -
- Show quoted text -
If I set the time in the CDateTimeCtrl using BOOL SetTime( const
CTime* pTimeNew ); the time value that is displayed will be adjusted
for the local time settings of the machine - it won't be a UTC
value.

For example if I get the current time at 1700 UTC on 1st July in UK
and ROI the displayed value will be 1800 as the control allows for
daylight saving. For most applications this is fine but in this case
I really want the values seen by the user to be UTC.

Allan
Victor
2008-01-21 20:09:24 UTC
Permalink
In this case you have to (as Ali already pointed out) explicitly convert the
local time to UTC BEFORE calling CDateTimeCtrl::SetTime

Victor
I don't think I quite understand the problem. If the user is entering the
time, then it is what they are entering, what does that have anything to do
with the timezone?
Say the user enters 10:52am UTC
When you call GetTime on the DateTime control, it will return a time struct
with todays date, 10:52am in the time. Why would you have to convert
anything?
Maybe I don't see the entire problem. Anyway CTime has a GetGmtTm, and there
is also TzSpecificLocalTimeToSystemTime (converts local time to a UTC time)
and of course SystemTimeToTzSpecificLocalTime.
AliR.
Ok, the problem is this; I am using a pair of CDateTimeCtrls one for
the date and one for hours/minutes/seconds. The problem I have is that
I need to work in UTC - all my internal calculations are using time_t
and the times shown to and selected by the user must be in UTC. I'm
getting into problems as the controls adjust for local time which I
don't want. I think I need to detect if an offset from UTC is in
effect and add/subtract that ammout when setting / reading from the
controls.
This is getting a bit ugly - can anyone think of a more elegant
solution?
Regards
Allan- Hide quoted text -
- Show quoted text -
If I set the time in the CDateTimeCtrl using BOOL SetTime( const
CTime* pTimeNew ); the time value that is displayed will be adjusted
for the local time settings of the machine - it won't be a UTC
value.

For example if I get the current time at 1700 UTC on 1st July in UK
and ROI the displayed value will be 1800 as the control allows for
daylight saving. For most applications this is fine but in this case
I really want the values seen by the user to be UTC.

Allan

Loading...