Exemplo n.º 1
0
            /// <summary>
            /// time_t is an int representing the number of seconds since Midnight UTC 1 Jan 1970 on the Gregorian Calendar.
            /// </summary>
            /// <param name="time_t"></param>
            /// <returns></returns>
            public static DateTime ToDateTime(int time_t)
            {
                DateTime convertedValue = origin + new TimeSpan(time_t * TimeSpan.TicksPerSecond);

                if (System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(convertedValue) == true)
                {
                    System.Globalization.DaylightTime daylightTime = System.TimeZone.CurrentTimeZone.GetDaylightChanges(convertedValue.Year);
                    convertedValue = convertedValue + daylightTime.Delta;
                }
                return(convertedValue);
            }
Exemplo n.º 2
0
        public static long ConvertToTimestamp(DateTime value)
        {
            TimeZoneInfo NYTimeZone = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time"); // (GMT+07:00) Bangkok, Hanoi, Jakarta
            DateTime     NyTime     = TimeZoneInfo.ConvertTime(value, NYTimeZone);
            TimeZone     localZone  = TimeZone.CurrentTimeZone;

            System.Globalization.DaylightTime dst = localZone.GetDaylightChanges(NyTime.Year);
            NyTime = NyTime.AddHours(-1);
            DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();
            TimeSpan span  = (NyTime - epoch);

            return((long)Convert.ToDouble(span.TotalSeconds));
        }
Exemplo n.º 3
0
            /// <summary>
            /// time_t is an int representing the number of seconds since Midnight UTC 1 Jan 1970 on the Gregorian Calendar.
            /// </summary>
            /// <param name="time"></param>
            /// <returns></returns>
            public static int To_time_t(DateTime time)
            {
                DateTime convertedValue = time;

                if (System.TimeZone.CurrentTimeZone.IsDaylightSavingTime(convertedValue) == true)
                {
                    System.Globalization.DaylightTime daylightTime = System.TimeZone.CurrentTimeZone.GetDaylightChanges(convertedValue.Year);
                    convertedValue = convertedValue - daylightTime.Delta;
                }
                long diff = convertedValue.Ticks - origin.Ticks;

                return((int)(diff / TimeSpan.TicksPerSecond));
            }
Exemplo n.º 4
0
        private int ConvertToTimestamp(DateTime value)
        {
            TimeZoneInfo NYTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
            DateTime     NyTime     = TimeZoneInfo.ConvertTime(value, NYTimeZone);
            TimeZone     localZone  = TimeZone.CurrentTimeZone;

            System.Globalization.DaylightTime dst = localZone.GetDaylightChanges(NyTime.Year);
            NyTime = NyTime.AddHours(-1);
            DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime();
            TimeSpan span  = (NyTime - epoch);

            return((int)Convert.ToDouble(span.TotalSeconds));
        }
Exemplo n.º 5
0
        private void WorkOutTime()
        {
            Invoke(new Action(() =>
            {
                // Get DaylightTime object
                System.Globalization.DaylightTime dl = curTimeZone.GetDaylightChanges(DateTime.Now.Year);

                // What is GMT (also called Coordinated Universal Time (UTC)
                DateTime curUTC = curTimeZone.ToUniversalTime(DateTime.Now);

                // What is GMT/UTC offset ?
                TimeSpan currentOffset = curTimeZone.GetUtcOffset(DateTime.Now);

                //----------------------------------------------------------------

                lbl_local_tz.Text = TimeZoneInfo.Local.DisplayName;

                // Difference between standard time and the daylight-saving time.
                TimeZoneInfo localZone = TimeZoneInfo.Local;
                string answer          = (localZone.BaseUtcOffset >= TimeSpan.Zero) ? "later" : "earlier";
                lbl_time_info.Text     = "Local time now is " + dl.Delta + " (hh:mm:ss) " + answer + " than UTC.";

                lbl_UTC.Text        = curUTC.ToString();
                lbl_local_time.Text = DateTime.Now.ToString();
                lbl_utc_offset.Text = currentOffset.ToString();

                lbl_DST_setting.Text = curTimeZone.IsDaylightSavingTime(DateTime.Now) ? "On" : "Off";
                lbl_dst_start.Text   = dl.Start.ToString();
                lbl_dst_ends.Text    = dl.End.ToString();

                lbl_timezone_name.Text = curTimeZone.StandardName;
                lbl_daylight_name.Text = curTimeZone.DaylightName;

                //---------------------------------------------------------------------------

                DateTime timeUtc = curTimeZone.ToUniversalTime(DateTime.Now);
                var dt           = DateTime.SpecifyKind(timeUtc, DateTimeKind.Utc);
                //TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
                TimeZoneInfo tZone = TimeZoneInfo.FindSystemTimeZoneById(cmbobx_tzones.SelectedItem.ToString());
                DateTime TheTime   = TimeZoneInfo.ConvertTimeFromUtc(dt, tZone);

                lbl_time_in_tz.Text = TheTime.ToString();
            }));
        }
Exemplo n.º 6
0
        public static bool _IsDaylightSavingTime_System_DateTime_System_Globalization_DaylightTime( )
        {
            //Parameters
            System.DateTime time = null;
            System.Globalization.DaylightTime daylightTimes = null;

            //ReturnType/Value
            System.Boolean returnVal_Real        = null;
            System.Boolean returnVal_Intercepted = null;

            //Exception
            Exception exception_Real        = null;
            Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnValue_Real = System.TimeZone.IsDaylightSavingTime(time, daylightTimes);
            }

            catch (Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnValue_Intercepted = System.TimeZone.IsDaylightSavingTime(time, daylightTimes);
            }

            catch (Exception e)
            {
                exception_Intercepted = e;
            }


            Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
Exemplo n.º 7
0
        private static System.DateTime GetBuildDateTime(System.Version version = null)
        {
            // 주.부.빌드.수정
            // 주 버전    Major Number
            // 부 버전    Minor Number
            // 빌드 번호  Build Number
            // 수정 버전  Revision NUmber

            //매개 변수가 존재할 경우
            if (version == null)
            {
                version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }

            //세번째 값(Build Number)은 2000년 1월 1일부터
            //Build된 날짜까지의 총 일(Days) 수 이다.
            int day = version.Build;

            System.DateTime dtBuild = (new System.DateTime(2000, 1, 1)).AddDays(day);

            //네번째 값(Revision NUmber)은 자정으로부터 Build된
            //시간까지의 지나간 초(Second) 값 이다.
            int intSeconds = version.Revision;

            intSeconds = intSeconds * 2;
            dtBuild    = dtBuild.AddSeconds(intSeconds);


            //시차 보정
            System.Globalization.DaylightTime daylingTime = System.TimeZone.CurrentTimeZone
                                                            .GetDaylightChanges(dtBuild.Year);
            if (System.TimeZone.IsDaylightSavingTime(dtBuild, daylingTime))
            {
                dtBuild = dtBuild.Add(daylingTime.Delta);
            }

            return(dtBuild);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            try
            {
                const string dataFmt     = "{0,-30}{1}";
                const string timeFmt     = "{0,-30}{1:MM-dd-yyyy HH:mm}";
                TimeZone     curTimeZone = TimeZone.CurrentTimeZone;
                // What is TimeZone name?
                System.Console.WriteLine(dataFmt, "TimeZone Name:", curTimeZone.StandardName);
                // Is TimeZone DayLight Saving?|
                System.Console.WriteLine(dataFmt, "Daylight saving time?", curTimeZone.IsDaylightSavingTime(DateTime.Now));
                // What is GMT (also called Coordinated Universal Time (UTC)
                DateTime curUTC = curTimeZone.ToUniversalTime(DateTime.Now);
                System.Console.WriteLine(timeFmt, "Coordinated Universal Time:", curUTC);
                // What is GMT/UTC offset ?
                TimeSpan currentOffset = curTimeZone.GetUtcOffset(DateTime.Now);
                System.Console.WriteLine(dataFmt, "UTC offset:", currentOffset);
                // Get DaylightTime object
                System.Globalization.DaylightTime dl = curTimeZone.GetDaylightChanges(DateTime.Now.Year);
                // DateTime when the daylight-saving period begins.
                System.Console.WriteLine("Start: {0:MM-dd-yyyy HH:mm} ", dl.Start);
                // DateTime when the daylight-saving period ends.
                System.Console.WriteLine("End: {0:MM-dd-yyyy HH:mm} ", dl.End);
                // Difference between standard time and the daylight-saving time.
                System.Console.WriteLine("delta: {0}", dl.Delta);
                System.Console.Read();

                //string input = "";
                //bool state = true;
                //var value = Environment.GetEnvironmentVariable("DOTNETBACKEND_PORT");
                //// If necessary, create it.
                //if (value == null)
                //{
                //    Environment.SetEnvironmentVariable("DOTNETBACKEND_PORT", "5567");


                //    // Now retrieve it.
                //    value = Environment.GetEnvironmentVariable("DOTNETBACKEND_PORT");
                //}
                //Environment.SetEnvironmentVariable("DOTNET_ASSEMBLY_SEARCH_PATHS", @"C:\WorkingFolder-Custom\TZ.BigDataScript\TZ.DataAnalyzer.Console\bin\Debug");
                //while (state)
                //{
                //    System.System.Console.WriteLine("Enter Query.");
                //    input = System.Console.ReadLine();
                //    AScript script = new AScript();
                //    script.Compile(input,"");

                //    //AntlrInputStream inputStream = new AntlrInputStream(input);
                //    //AScriptLexer exprL = new AScriptLexer(inputStream);
                //    //CommonTokenStream commonTokenStream = new CommonTokenStream(exprL);
                //    //AScriptParser expPar = new AScriptParser(commonTokenStream);

                //    //// exprParser.GroupdataContext getContext = expPar.groupdata();
                //    //AScriptParser.StatementContext getContext = expPar.statement();
                //    //AScriptVisitor visitor = new AScriptVisitor();
                //    //visitor.Visit(getContext);

                //    //foreach (var line in visitor.Lines)
                //    //{
                //    //    System.System.Console.WriteLine("{0   } has said {1}  ", line.Person, line.Text);
                //    //}
                //    //// var item= System.Console.ReadLine();
                //    //if (input == "exist")
                //    //{
                //    //    state = false;
                //    //}
                //    //else
                //    //{
                //    //    state = true;
                //    //}
                //}
            }
            catch (Exception ex)
            {
            }
            finally
            {
                System.Console.ReadLine();
            }
        }
 public static bool IsDaylightSavingTime(DateTime time, System.Globalization.DaylightTime daylightTimes)
 {
 }
 public static bool IsDaylightSavingTime(System.DateTime time, System.Globalization.DaylightTime daylightTimes)
 {
     return(default(bool));
 }