當前位置: 首頁>>代碼示例>>C#>>正文


C# DateTime.ToLocalTime方法代碼示例

本文整理匯總了C#中System.DateTime.ToLocalTime方法的典型用法代碼示例。如果您正苦於以下問題:C# DateTime.ToLocalTime方法的具體用法?C# DateTime.ToLocalTime怎麽用?C# DateTime.ToLocalTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.ToLocalTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExchangeKmhInOrders

        public static string ExchangeKmhInOrders(List<Guid> orderArticles, DateTime timeStamp, Guid prodNomenId, TechnDatesSpeciality speciality)
        {
            using (ProductProvider provider = new ProductProvider())
            {
                var dates = from date in provider.TechnDates
                            where orderArticles.Contains(date.OrderArticleID)
                            && date._dictNomenID == prodNomenId
                            select date;
                foreach (var date in dates)
                {
                    switch (speciality)
                    {
                        case TechnDatesSpeciality.Main:
                            date.gen_date = timeStamp.ToLocalTime();
                            break;
                        case TechnDatesSpeciality.Svar:
                            date.svar_date = timeStamp.ToLocalTime();
                            break;
                        case TechnDatesSpeciality.Him:
                            date.him_date = timeStamp.ToLocalTime();
                            break;
                        case TechnDatesSpeciality.Techn:
                            date.techn_date = timeStamp.ToLocalTime();
                            break;
                    }
                }

                provider.SubmitChanges();
            }

            return new PostResult("Ok", 0).ToString();
        }
開發者ID:vahtel65,項目名稱:Aspect_loc,代碼行數:32,代碼來源:TechnDates.aspx.cs

示例2: JsonToDateTime

 public DateTime JsonToDateTime(string jsonDate)
 {
     string value = jsonDate.Substring(6, jsonDate.Length - 8);
     DateTimeKind kind = DateTimeKind.Utc;
     int index = value.IndexOf('+', 1);
     if (index == -1)
         index = value.IndexOf('-', 1);
     if (index != -1)
     {
         kind = DateTimeKind.Local;
         value = value.Substring(0, index);
     }
     long javaScriptTicks = long.Parse(value, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture);
     long InitialJavaScriptDateTicks = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;
     DateTime utcDateTime = new DateTime((javaScriptTicks * 10000) + InitialJavaScriptDateTicks, DateTimeKind.Utc);
     DateTime dateTime;
     switch (kind)
     {
         case DateTimeKind.Unspecified:
             dateTime = DateTime.SpecifyKind(utcDateTime.ToLocalTime(), DateTimeKind.Unspecified);
             break;
         case DateTimeKind.Local:
             dateTime = utcDateTime.ToLocalTime();
             break;
         default:
             dateTime = utcDateTime;
             break;
     }
     return dateTime;
 }
開發者ID:drawde,項目名稱:DidYouSeeMyLittleBear,代碼行數:30,代碼來源:Main.Master.cs

示例3: DateTimeKindHandling

        public void DateTimeKindHandling()
        {
            DateTime value = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);

              MemoryStream ms = new MemoryStream();
              BsonWriter writer = new BsonWriter(ms);

              writer.WriteStartObject();
              writer.WritePropertyName("DateTime");
              writer.WriteValue(value);
              writer.WriteEndObject();

              byte[] bson = ms.ToArray();

              JObject o;
              BsonReader reader;

              reader = new BsonReader(new MemoryStream(bson), false, DateTimeKind.Utc);
              o = (JObject)JToken.ReadFrom(reader);
              Assert.AreEqual(value, (DateTime)o["DateTime"]);

              reader = new BsonReader(new MemoryStream(bson), false, DateTimeKind.Local);
              o = (JObject)JToken.ReadFrom(reader);
              Assert.AreEqual(value.ToLocalTime(), (DateTime)o["DateTime"]);

              reader = new BsonReader(new MemoryStream(bson), false, DateTimeKind.Unspecified);
              o = (JObject)JToken.ReadFrom(reader);
              Assert.AreEqual(DateTime.SpecifyKind(value.ToLocalTime(), DateTimeKind.Unspecified), (DateTime)o["DateTime"]);
        }
開發者ID:AndyStewart,項目名稱:docsharp,代碼行數:29,代碼來源:BsonReaderTests.cs

示例4: ChangeDSTFromWinterToSummerToWinter

 public void ChangeDSTFromWinterToSummerToWinter()
 {
     var dateTime = new DateTime(2015, 10, 25, 1, 30, 0, DateTimeKind.Utc);
     var timeInput = new CnDTimeInput();
     timeInput.SelectedDateTime = dateTime.ToLocalTime();
     Assert.That(timeInput.IsSummerPeriod, Is.EqualTo(false));
     timeInput.SelectedDateTime = dateTime.AddHours(-1).ToLocalTime();
     Assert.That(timeInput.IsSummerPeriod, Is.EqualTo(true));
     timeInput.SelectedDateTime = dateTime.ToLocalTime();
     Assert.That(timeInput.IsSummerPeriod, Is.EqualTo(false));
 }
開發者ID:CITnDev,項目名稱:CnDTimeControls,代碼行數:11,代碼來源:DaylightSavingTests.cs

示例5: StartSession

        public void StartSession(InstalledGame game, DateTime startDateTime)
        {
            Icon = game.Icon;
            TabText = game.Name;
            CloseButton = false;
            CloseButtonVisible = false;

            this.pictureBoxArt.Image = game.Image;
            this.labelGameName.Text = game.Name;
            this.labelStartedPlaying.Text = string.Format ("Started playing on {0} at {1}",
                startDateTime.ToLocalTime().ToShortDateString (), startDateTime.ToLocalTime().ToShortTimeString ());
            this.labelIdle.Text = "";
        }
開發者ID:kevinbrill,項目名稱:tempusgameit-client,代碼行數:13,代碼來源:ActiveSessionControl.cs

示例6: GetBuildNumber

        //Code PES
        private string GetBuildNumber()
        {
            string strBuildNumber = string.Empty, timestamp = string.Empty;
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dtDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            dtDate = dtDate.AddSeconds(secondsSince1970);
            dtDate = dtDate.ToLocalTime();
            timestamp = dtDate.ToString("yyyyMMddHHmmss");
            if (timestamp == string.Empty)
            { timestamp = "UNKOWN!"; }
            strBuildNumber = "Build  : " + timestamp;
            return strBuildNumber;
        }
開發者ID:santoshsaha,項目名稱:AxiomCS-Ribbon,代碼行數:34,代碼來源:About.xaml.cs

示例7: getDescriptionForTime

        private string getDescriptionForTime(DateTime startTime)
        {
            if (startTime < DateTime.UtcNow)
                return "On Now";

            return "Starting at " + startTime.ToLocalTime().ToShortTimeString();
        }
開發者ID:jorik041,項目名稱:NycCodeCamp6,代碼行數:7,代碼來源:CampOverviewViewModel.cs

示例8: RoundTime

        // 按照時間單位,把時間值零頭去除,正規化,便於後麵計算差額
        /// <summary>
        /// 按照時間基本單位,去掉零頭,便於互相計算(整單位的)差額。
        /// 算法是先轉換為本地時間,去掉零頭,再轉換回 GMT 時間
        /// </summary>
        /// <param name="strUnit">時間單位。day/hour之一。如果為空,相當於 day</param>
        /// <param name="time">要處理的時間。為 GMT 時間</param>
        /// <param name="strError">返回出錯信息</param>
        /// <returns>-1: 出錯; 0: 成功</returns>
        public static int RoundTime(string strUnit,
    ref DateTime time,
    out string strError)
        {
            strError = "";

            time = time.ToLocalTime();
            if (strUnit == "day" || string.IsNullOrEmpty(strUnit) == true)
            {
                time = new DateTime(time.Year, time.Month, time.Day,
                    12, 0, 0, 0);
            }
            else if (strUnit == "hour")
            {
                time = new DateTime(time.Year, time.Month, time.Day,
                    time.Hour, 0, 0, 0);
            }
            else
            {
                strError = "未知的時間單位 '" + strUnit + "'";
                return -1;
            }
            time = time.ToUniversalTime();
            return 0;
        }
開發者ID:renyh1013,項目名稱:dp2,代碼行數:34,代碼來源:DateTimeUtil.cs

示例9: Form1

        public Form1()
        {
            _heartbeat = 0;
            InitializeComponent();
            this.WindowState = FormWindowState.Minimized;
            icnStopped = Resources.Icon1;
            icnStarted = Resources.Icon2;

            timestamp = Utils.RetrieveLinkerTimestamp();

            // notifyIcon1.Text = "MTC Multi-SHDR Agent - Release " + _assembly.ImageRuntimeVersion ;
            notifyIcon1.Text = "Autostart MTC SHDR Agent - Release " + timestamp.ToLocalTime(); ;
            notifyIcon1.Icon = icnStopped;

            Utilities.Logger.RestartLog();
            aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
               // System.Threading.Thread.Sleep(30000);

            MTConnectAgentCore.Configuration.defaultDirectory = Application.StartupPath + "\\";
            MTConnectAgentCore.Configuration.confDirectory = "" ;

            SystemEvents.SessionEnding += SystemEvents_SessionEnding;
            Reset();
        }
開發者ID:Wolfury,項目名稱:MTConnect4OPC,代碼行數:25,代碼來源:Form1.cs

示例10: FromUnixTime

        public static DateTime FromUnixTime(this long seconds)
        {
            var time = new DateTime(1970, 1, 1);
            time = time.AddSeconds(seconds);

            return time.ToLocalTime();
        }
開發者ID:RestRT,項目名稱:RestRT,代碼行數:7,代碼來源:TimeExtensions.cs

示例11: ConvertFromDate

 public override String ConvertFromDate(DateTime value)
 {
     value = value.ToLocalTime();
     var date = String.Format(CultureInfo.InvariantCulture, "{0:0000}-{1:00}-{2:00}", value.Year, value.Month, value.Day);
     var time = String.Format(CultureInfo.InvariantCulture, "{0:00}:{1:00}:{2:00},{3:000}", value.Hour, value.Minute, value.Second, value.Millisecond);
     return String.Concat(date, "T", time);
 }
開發者ID:JBTech,項目名稱:AngleSharp,代碼行數:7,代碼來源:DatetimeLocalInputType.cs

示例12: ConvertTicksToDateTime

        public static DateTime ConvertTicksToDateTime(long ticks)
        {
            var date = new DateTime(1970, 1, 1);
            date = date.AddSeconds(ticks);

            return date.ToLocalTime();
        }
開發者ID:ukionik,項目名稱:EasyMessenger,代碼行數:7,代碼來源:UnixDateTimeConverter.cs

示例13: ApplicationLastUpdate

    public static DateTime ApplicationLastUpdate()
    {
        #region Variable
        string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
        const int c_PeHeaderOffset = 60;
        const int c_LinkerTimestampOffset = 8;
        byte[] b = new byte[2048];
        System.IO.Stream s = null;
        DateTime dttm = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        #endregion
        #region Procedure
        try
        {
            s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            s.Read(b, 0, 2048);
        }
        finally
        {
            if (s != null)
            {
                s.Close();
            }
        }

        int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
        int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
        dttm = dttm.AddSeconds(secondsSince1970);
        dttm = dttm.ToLocalTime();
        #endregion

        return dttm;
    }
開發者ID:oofdui,項目名稱:GooDatabaseViewer,代碼行數:32,代碼來源:clsGlobalNative.cs

示例14: datetime_kind_can_change_based_on_usage

        public void datetime_kind_can_change_based_on_usage()
        {
            var originalDate = new DateTime(2012, 7, 1, 12, 0, 0);

            // An unspecified time can be change to a local time. .NET
            // will assume that the original value was universal.
            var local = originalDate.ToLocalTime();
            Assert.AreNotEqual(originalDate, local);
            Assert.AreEqual(DateTimeKind.Local, local.Kind);
            Assert.AreEqual(originalDate.AddHours(-4), local);
            Assert.AreEqual(DateTimeKind.Unspecified, originalDate.Kind);

            // An unspecified time can be change to a universal time. .NET
            // will assume that the original value was local.
            var utc = originalDate.ToUniversalTime();
            Assert.AreNotEqual(originalDate, utc);
            Assert.AreEqual(DateTimeKind.Utc, utc.Kind);
            Assert.AreEqual(originalDate.AddHours(4), utc);
            Assert.AreEqual(DateTimeKind.Unspecified, originalDate.Kind);

            // So, according to .NET, 2 AM GMT and 2 AM in the current time
            // zone are the same thing. Pay no attention that they're different
            // by 4 hours (or 5 in the winter)!
            var utc2am = new DateTime(2012, 9, 26, 2, 0, 0, DateTimeKind.Utc);
            var local2am = new DateTime(2012, 9, 26, 2, 0, 0, DateTimeKind.Local);
            Assert.AreEqual(utc2am, local2am);
        }
開發者ID:jarrettmeyer,項目名稱:sandbox,代碼行數:27,代碼來源:DateTime_Tests.cs

示例15: GetBulidTime

        public static DateTime GetBulidTime()
        {
            var filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int cPeHeaderOffset = 60;
            const int cLinkerTimestampOffset = 8;
            var b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            var i = BitConverter.ToInt32(b, cPeHeaderOffset);
            var secondsSince1970 = BitConverter.ToInt32(b, i + cLinkerTimestampOffset);
            var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.ToLocalTime();
            return dt;
        }
開發者ID:Anuchap,項目名稱:NUtils,代碼行數:28,代碼來源:AppInfo.cs


注:本文中的System.DateTime.ToLocalTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。