当前位置: 首页>>代码示例>>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;未经允许,请勿转载。