Windows CE 5.0 - Time Zone

X

Xavier PACOTTE

Hello,

I would like to modify the time zone by program under windows ce.net 5.0.
I tried with the opennetcf librairy, it works under 4.2 but not under 5.0.

How can I modifiy this parameter?

Best regards.
 
P

Paul G. Tobey [eMVP]

"Works" and "doesn't work" is pretty useless information. What actually
happens?

The same call would be used in CE5 as in CE4.x to change the time zone
characteristics, SetTimeZoneInformation(). The parameters to the call have
not changed. You must be doing something wrong, but with the little
information you've given, I can't imagine what it is.

Also, what exactly are you trying to accomplish? I think that every time
zone in the world is already in the registry in CE5. Why would you need to
'change' it?

Paul T.
 
X

Xavier PACOTTE

Hello,

In fact, my collegue made a configuration application (for windows ce 4.2)
which configured all parameters
of system as the time zone when we installed a another program.

I need to synchronise datas with a server and I am in France, therefore I
want to change the default parameter.
The server sends the date and hour for the device.
I tried this code under windows ce 5.0, but the
RechercheFuseauHoraire("timezone")function returned always false.

the code :
---------------------------------------------------------------------------------------
public static bool RechercheFuseauHoraire(string pFuseauRech)
{
TimeZoneInformation tzi = null;

try
{
if (DateTimeEx.GetTimeZoneInformation(ref tzi) !=
TimeZoneState.Unknown)
{
if (EnleveCaracNull(tzi.StandardName) ==
pFuseauRech.Trim())
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
catch
{
return false;
}
}

/// <summary>
/// Modifie le fuseau horaire utilisé par Windows
/// </summary>
/// <param name="pFuseau">Nom standard du fuseau horaire à
utiliser</param>
/// <returns>True si OK, False sinon</returns>
public static bool DefinitFuseauHoraire(string pFuseau)
{
TimeZoneCollection lstTimeZone;

try
{
lstTimeZone = new TimeZoneCollection();
lstTimeZone.Initialize(1);
// On parcourt la liste des fuseaux possibles
foreach (TimeZoneInformation objTimezone in lstTimeZone)
{

// Une fois qu'on a trouvé le fuseau à appliquer...
if (EnleveCaracNull(objTimezone.StandardName.Trim()) ==
pFuseau.Trim())
{
//... on le définit comme fuseau utilisé par
Windows...
OpenNETCF.Win32.TimeZoneInformation tzi = new TimeZoneInformation();

DateTimeEx.SetTimeZoneInformation(objTimezone);
//... et on force le système à rafraîchir la variable d'environnement
qui définit
// le nom du fuseau utilisé
FieldInfo fi =
typeof(TimeZone).GetField("currentTimeZone",
BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.Instance);
fi.SetValue(null, null);

return true;
}

}
return false;

}
catch
{
return false;
}
}
 
P

Paul G. Tobey [eMVP]

Well, the RechercheFuseauHoraire() function looks fine. Won't work any
different on CE4.x and 5.0.

The function DefinitFuseauHoraire(), however, is behaving in an absolutely
insane manner. Again, *what* modification are you trying to make? You just
want to set the time zone to something at GMT+1hour? You're calling
TimeZoneCollection.Initialize() with the wrong parameter for that. Please
read the documentation. What name are you passing to
DefinitFuseauHoraire(), also? Where did the name come from? If it did not
come from a TimeZoneCollection earlier, there's a pretty high probability
that the name won't match anything in the TimeZoneCollection you're trying
to build.

Also, if you want to set the current time zone, you would absolutely,
positively not do anything remotely like this:
FieldInfo fi =
typeof(TimeZone).GetField("currentTimeZone",
BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.Instance);
fi.SetValue(null, null);

Once you have a TimeZoneInformation instance, which you can get from the
TimeZoneCollection based on whatever selection criteria you want.

TimeZoneInformation tzi = <selected somehow from a
TimeZoneCollection>;

TimeZone.SetTimeZoneInformation( tzi );

Simple as it can possibly be.

Paul T.

Xavier PACOTTE said:
Hello,

In fact, my collegue made a configuration application (for windows ce 4.2)
which configured all parameters
of system as the time zone when we installed a another program.

I need to synchronise datas with a server and I am in France, therefore I
want to change the default parameter.
The server sends the date and hour for the device.
I tried this code under windows ce 5.0, but the
RechercheFuseauHoraire("timezone")function returned always false.

the code :
---------------------------------------------------------------------------------------
public static bool RechercheFuseauHoraire(string pFuseauRech)
{
TimeZoneInformation tzi = null;

try
{
if (DateTimeEx.GetTimeZoneInformation(ref tzi) !=
TimeZoneState.Unknown)
{
if (EnleveCaracNull(tzi.StandardName) ==
pFuseauRech.Trim())
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
catch
{
return false;
}
}

/// <summary>
/// Modifie le fuseau horaire utilisé par Windows
/// </summary>
/// <param name="pFuseau">Nom standard du fuseau horaire à
utiliser</param>
/// <returns>True si OK, False sinon</returns>
public static bool DefinitFuseauHoraire(string pFuseau)
{
TimeZoneCollection lstTimeZone;

try
{
lstTimeZone = new TimeZoneCollection();
lstTimeZone.Initialize(1);
// On parcourt la liste des fuseaux possibles
foreach (TimeZoneInformation objTimezone in lstTimeZone)
{

// Une fois qu'on a trouvé le fuseau à appliquer...
if (EnleveCaracNull(objTimezone.StandardName.Trim()) ==
pFuseau.Trim())
{
//... on le définit comme fuseau utilisé par
Windows...
OpenNETCF.Win32.TimeZoneInformation tzi = new TimeZoneInformation();

DateTimeEx.SetTimeZoneInformation(objTimezone);
//... et on force le système à rafraîchir la variable d'environnement
qui définit
// le nom du fuseau utilisé
FieldInfo fi =
typeof(TimeZone).GetField("currentTimeZone",
BindingFlags.NonPublic|BindingFlags.Static|BindingFlags.Instance);
fi.SetValue(null, null);

return true;
}

}
return false;

}
catch
{
return false;
}
}

---------------------------------------------------------------------------------------
Best regards.

"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> a écrit dans le message de (e-mail address removed)...
"Works" and "doesn't work" is pretty useless information. What actually
happens?

The same call would be used in CE5 as in CE4.x to change the time zone
characteristics, SetTimeZoneInformation(). The parameters to the call
have not changed. You must be doing something wrong, but with the little
information you've given, I can't imagine what it is.

Also, what exactly are you trying to accomplish? I think that every time
zone in the world is already in the registry in CE5. Why would you need
to 'change' it?

Paul T.
 
P

Paul G. Tobey [eMVP]

Sorry about that. I had the right code in front of me, but mistyped it into
the message:
TimeZoneInformation tzi = <selected somehow from a
TimeZoneCollection>;

DateTimeEx.SetTimeZoneInformation( tzi );

Paul T.
 

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