473,378 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ManagementDateTimeConverter in C# .Net windows application

53
Hello All,

I am having an C#.Net windows application.There I am using WMI class Win32_OperatingSystem to get the information of operating system. In this class we are having a Parameter Called "LocalDateTime".
If the time zone is "(GMT+5:30) chennai,kolkata,Mumbai,Newdelhi" we will get localdatetime from WMI as "20070327182923.82800+330" . This value I have converted to datetime by using ManagementDateTimeConverter
DateTime Dt;
Dt = ManagementDateTimeConverter.ToDateTime
string strFormatedDate = Dt.ToString("MMM/dd/yyyy hh:mm:ss tt");
("20070327182923.82800+330"); This is working fine and giving the result like Mar/27/2008 06:29:23

the problem comes If I change the Time zone, Then i tried get the localdatetime dynamically , WMI is returning the correct value , but the ManagementDateTimeConverter is not giving the correct value.It is giving the previous time zone value only.

But when i close the appliaction and run it again then it is giving current timezone time what ever we have selected.

What is the problem here? can anyone give any solution to get current time zone time.

Thanks in advance...
Mar 27 '08 #1
1 2312
Plater
7,872 Expert 4TB
Why not just use DateTime.Parse() ?

DateTime dt = DateTime.Parse("20070327182923.82800+330" );

Should give you a datetime object of the correct value.



Also, there seems to be some CLR caching involved with timezone information.
You can do something like the following to reset what the cached timezone is.

Expand|Select|Wrap|Line Numbers
  1. try
  2. {//System.Reflection.
  3.    FieldInfo fi = typeof(TimeZone).GetField("currentTimeZone", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
  4.    fi.SetValue(null, null);
  5. }
  6. catch (Exception ee)
  7. {
  8. }
  9.  
Mar 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael | last post by:
Hi, I have a windows service developed using c# and it needs to lunch another windows application. I have been trying to use Process class to do it but the problem is becase windows service...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
5
by: pberna | last post by:
Dear all, I built a Web Form application to start and stop a Windows Service remotely. I successful tested the application on Windows 2000 server + IIS. I must include the ASPNET user to the...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.