Click here to Skip to main content
15,915,328 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionApplication Architecture Pin
radasys2-Sep-05 3:51
radasys2-Sep-05 3:51 
AnswerRe: Application Architecture Pin
radasys5-Sep-05 0:38
radasys5-Sep-05 0:38 
Question.Net and HtmlHelp function Pin
daisyliu1-Sep-05 6:34
daisyliu1-Sep-05 6:34 
QuestionTimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Matt Casto1-Sep-05 6:17
Matt Casto1-Sep-05 6:17 
AnswerRe: TimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Matt Casto2-Sep-05 4:59
Matt Casto2-Sep-05 4:59 
AnswerRe: TimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Richard Deeming5-Sep-05 8:17
mveRichard Deeming5-Sep-05 8:17 
GeneralRe: TimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Matt Casto5-Sep-05 15:32
Matt Casto5-Sep-05 15:32 
GeneralRe: TimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Richard Deeming5-Sep-05 23:50
mveRichard Deeming5-Sep-05 23:50 
If you just need the current UTC system time, you can simply call DateTime.UtcNow, which will return the same time as calling the GetSystemTime API.

From your initial post, it sounded like you need the current time zone information as well, in which case the code I posted will be the simplest solution.

If you want the current time zone information without any caching, you can simply remove the caching code and always return a new instance:
C#
using System;
using System.Reflection;
 
public sealed class CurrentTimeZone
{
    private static readonly Type _timeZoneType;
    private static readonly ConstructorInfo _timeZoneConstructor;
    
    static CurrentTimeZone()
    {
        _timeZoneType = TimeZone.CurrentTimeZone.GetType();
        _timeZoneConstructor = _timeZoneType.GetConstructor(
            BindingFlags.Instance | BindingFlags.NonPublic,
            null, new Type[0], null);
    }
    
    private static TimeZone CreateInstance()
    {
        return (TimeZone)_timeZoneConstructor.Invoke(null);
    }
    
    public static TimeZone Instance
    {
        get { return CreateInstance(); }
    }
}



"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
GeneralRe: TimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Matt Casto6-Sep-05 1:17
Matt Casto6-Sep-05 1:17 
GeneralRe: TimeZone.CurrentTimeZone not updated when machine's time zone changes. Pin
Richard Deeming6-Sep-05 6:57
mveRichard Deeming6-Sep-05 6:57 
Question[security] setting dynamically the proxy.Credentials with the currentIdentity Pin
joaoPaulo1-Sep-05 3:36
joaoPaulo1-Sep-05 3:36 
Questionlook for some options which can pass through firewall Pin
at2000131-Aug-05 16:35
at2000131-Aug-05 16:35 
AnswerRe: look for some option witch can pass through firewall Pin
Andy Brummer31-Aug-05 17:55
sitebuilderAndy Brummer31-Aug-05 17:55 
GeneralRe: look for some option witch can pass through firewall Pin
at2000131-Aug-05 23:52
at2000131-Aug-05 23:52 
GeneralRe: look for some option witch can pass through firewall Pin
Andy Brummer1-Sep-05 3:34
sitebuilderAndy Brummer1-Sep-05 3:34 
QuestionExtracting Frames From The AVI Movie Pin
Nabeel Younus Khan31-Aug-05 11:04
Nabeel Younus Khan31-Aug-05 11:04 
QuestionWindows Service arguments Pin
vSoares31-Aug-05 5:44
professionalvSoares31-Aug-05 5:44 
QuestionPicture Box control for .NET PocketPC application Pin
Sevugan31-Aug-05 5:13
Sevugan31-Aug-05 5:13 
AnswerRe: Picture Box control for .NET PocketPC application Pin
Terry Dong31-Aug-05 16:15
Terry Dong31-Aug-05 16:15 
Questiontapi problem Pin
iram130-Aug-05 18:45
iram130-Aug-05 18:45 
Question.Net and Memory Resources Pin
Stanciu Vlad30-Aug-05 10:49
Stanciu Vlad30-Aug-05 10:49 
AnswerRe: .Net and Memory Resources Pin
Dave Kreskowiak30-Aug-05 12:04
mveDave Kreskowiak30-Aug-05 12:04 
GeneralRe: .Net and Memory Resources Pin
Stanciu Vlad30-Aug-05 19:40
Stanciu Vlad30-Aug-05 19:40 
GeneralRe: .Net and Memory Resources Pin
immes31-Aug-05 0:08
immes31-Aug-05 0:08 
GeneralRe: .Net and Memory Resources Pin
Stanciu Vlad31-Aug-05 1:48
Stanciu Vlad31-Aug-05 1:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.