Handle different international time zones for Item.Start and Item.

M

masani paresh

Hi Friends,

My mail goal is to get the UTC time for local zone. I am facing problems in
handling internation time zones in VBScript for Item.Start and Item.End.
Could any one tell me in brief/code to handle different international time
zones. I thought of the below solution:

1. Get the UTC time
2. Get the time difference with local zone
3. Add it to UTC.

Is there any ways to do this in VBScript?

Thanks in Advance,
Megha
 
K

Ken Slovak - [MVP - Outlook]

You'd need to use WSH (Windows Scripting) to read the registry to get those
settings.
 
M

masani paresh

We can do it in VB like below:

Dim testTime As DateTime = DateTime.Now
Debug.WriteLine(testTime.ToString)
Debug.WriteLine(testTime.ToUniversalTime.ToString)

Is there any function in VBScript that can convert local time to UTC?

Thanks,
Paresh
 
K

Ken Slovak - [MVP - Outlook]

That's using VB.NET.

There are no equivalents in VBScript or Windows scripting for
ToUniveralTime().

You'd have to write your own function for that. Or you could search on the
Web to see if anything like that has been done using VBScript or possibly
VBA or VB6. If you found code in VB6 or VBA you'd need to translate it into
VBScript code.
 
M

masani paresh

Thanks Ken, I have done it in following way.

sTime = Format(Item.Start,"yyyy-mm-dd" & "T" & "hh:mm:ss" & "+" & timeOffset)
eTime = Format(Item.End,"yyyy-mm-dd" & "T" & "hh:mm:ss" & "+" & timeOffset)

I have hard coded time offsets for different time zone that is required. I
am getting local site and corresponding time zone offset and adding it to
current time to get the UTC.

Could you see any improvement that i can make here.

Thanks,
Paresh
 
D

Dmitry Streblechenko

Keep in mind that the offsets will be different depending on whether
Daylight Savings Time (DST) is observed and whether the given date falls
with the DST.
Keep in mind that on the MAPI level, these propertiss are already stored in
UTC, so you can simply access teh raw MAPI properties using Extended MAPI,
CDO 1.21, or Redemption.
<plug> Redemption (url below) exposes time zones through the
RDOSession.Timeszones collection -
http://www.dimastr.com/redemption/rdo/rdotimezones.htm </plug>

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
K

Ken Slovak - [MVP - Outlook]

I'd agree with Dmitry that you aren't handling DST dates and hard coding
offsets is not a good way to go.
 
M

masani paresh

Dmitry, You are right. I used following code to get the time zone but it says
"ActiveX component cannot create object: Redeption.RDOSession" Could you help
me.

set Session = CreateObject("Redemption.RDOSession")
set Timezones = Session.Timezones
for each TZ in Timezones
MsgBox TZ.Name
next

Thanks,
Paresh
 
M

masani paresh

Hi Ken,
I have written following steps to get the UTC value of current time by
reading reg keys. But when it executes the set oShell =
CreateObject("WScript.Shell") statement, it show the dialog box for
confirming some installation. I have to click yes then it will proceed and
works fine. Could you tell me how to make this statement to work silently.

startTime = Item.Start
endTime = Item.End
set oShell = CreateObject("WScript.Shell")
atb = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\" &_
"Control\TimeZoneInformation\ActiveTimeBias"
offsetMin = oShell.RegRead(atb)
startTime = dateadd("n", offsetMin, startTime)
endTime = dateadd("n", offsetMin, endTime)

startTime = Format(startTime,"yyyy-mm-dd" & "T" & "hh:mm:ss" & "Z")
endTime = Format(endTime,"yyyy-mm-dd" & "T" & "hh:mm:ss" & "Z")
MsgBox startTime & vbcrlf & endTime

Thanks,
Paresh
 
K

Ken Slovak - [MVP - Outlook]

It shouldn't if WSH is installed already. I never get that prompt when
instantiating a WSH object.

What happens if you try that line from a simple VBS file you can create
using Notepad? Do you always get the same prompt:

Set oShell = CreateObject("WScript.Shell")
 
K

Ken Slovak - [MVP - Outlook]

Is Redemption registered on that machine? Does New work?

Are you running any script stopper from A-V or firewall software that might
be preventing CreateObject() from working?
 
M

masani paresh

Do you always get the same prompt:
Not always. I got it first time when I ran the customized outlook form. And
I also got it when I ran it after restarting my machine.

Thanks,
Paresh
 
M

masani paresh

How do I verify whether Redemption registered or not on my machine?

Thanks,
Paresh
 
K

Ken Slovak - [MVP - Outlook]

One way would be just to register it. Another would be to look in the
registry under HKCR and see if the Redemption classes are registered there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top