VMware {code} Community
derekevn
Contributor
Contributor
Jump to solution

How do I get current time and timezone local to an ESX server via SDK?

In both the 3.0/2.0 SDK and 3.5/2.5 SDK, when I use the CurrentTime method against my ServiceInstance object, the timezone returned is always "Greenwich Mean Time" and the daylight savings flag is not set. The time reported, however, has been adjusted to be in my client's timezone (off by the number of minutes that are different between servers on top of the timezone difference). I need to know the timezone of the server and the actual unadjusted time. (as an aside, the serverClock property also shows GMT).

For example, the server shows a time of 11:38 AM CDT. My client is 9:35 AM PDT. CurrenTime returns 9:38 AM GMT. I want it to return 11:38 CDT!

0 Kudos
1 Solution

Accepted Solutions
akutz
Hot Shot
Hot Shot
Jump to solution

A few things:

- CurrentDateTime should return a GMT value. I checked the MOB and this seems to be true. Perhaps your client was massaging the value before you actually saw it?

As you can see, the time is 12:xx and my time is actually 7AM, hence GMT - CDT (5 hours).

- CurrentDateTime does not seem to be the only method you can use to get time values. There is also the QueryDateTime method defined on the HostDateTimeSystem object, and you can get a list of time zones available to the host with QueryAvailableTimeZones.

Hope this helps!

View solution in original post

0 Kudos
6 Replies
admin
Immortal
Immortal
Jump to solution

The only method returning the current time on the server is CurrentTime, defined on ServiceInstance. Another property associated with fetching server time is serverClock, thouh it is best used for monitoring the change in time. Unfortunately, there is no method available specificifically for returning only the timezone of the server.

I have used the following and successfully fetched the current time of the esx server.

Util::connect();

my $service_instance = Vim::get_service_instance();

$service_instance->CurrentTime();

0 Kudos
derekevn
Contributor
Contributor
Jump to solution

Thanks, but I am using CurrentTime(). My problem is that it does not return the correct time on the server. It is returning an adjusted time based on the client's timezone. Is your server and client in the same or different timezones?

Another observation is that the time structure from CurrentTime() indicates GMT, but the time returned is not GMT, it is the local time zone. Does your return from CurrentTime show GMT or does it show the correct server timezone?

0 Kudos
akutz
Hot Shot
Hot Shot
Jump to solution

A few things:

- CurrentDateTime should return a GMT value. I checked the MOB and this seems to be true. Perhaps your client was massaging the value before you actually saw it?

As you can see, the time is 12:xx and my time is actually 7AM, hence GMT - CDT (5 hours).

- CurrentDateTime does not seem to be the only method you can use to get time values. There is also the QueryDateTime method defined on the HostDateTimeSystem object, and you can get a list of time zones available to the host with QueryAvailableTimeZones.

Hope this helps!

0 Kudos
derekevn
Contributor
Contributor
Jump to solution

Thanks. It looks like these query methods are new for VI SDK 2.5. I haven't upgraded yet, but will play around with it as soon as I do.

0 Kudos
tos2k
Expert
Expert
Jump to solution

Hi!

just found the timezone definition for a ESX host here:

Data Object Type: HostDateTimeSystemTimeZone

Parent Managed Object ID: host-8561

Property Path: config.dateTimeInfo.timeZone

Tos2k

derekevn
Contributor
Contributor
Jump to solution

Well, it looks like most of this has been addressed in SDK 2.5. I guess I'll need to upgrade sooner than later.

Thanks!

0 Kudos