久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='nqWl9'><style id='nqWl9'><dir id='nqWl9'><q id='nqWl9'></q></dir></style></legend>

  • <i id='nqWl9'><tr id='nqWl9'><dt id='nqWl9'><q id='nqWl9'><span id='nqWl9'><b id='nqWl9'><form id='nqWl9'><ins id='nqWl9'></ins><ul id='nqWl9'></ul><sub id='nqWl9'></sub></form><legend id='nqWl9'></legend><bdo id='nqWl9'><pre id='nqWl9'><center id='nqWl9'></center></pre></bdo></b><th id='nqWl9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nqWl9'><tfoot id='nqWl9'></tfoot><dl id='nqWl9'><fieldset id='nqWl9'></fieldset></dl></div>

  • <tfoot id='nqWl9'></tfoot>

    <small id='nqWl9'></small><noframes id='nqWl9'>

        <bdo id='nqWl9'></bdo><ul id='nqWl9'></ul>

        來自不同格式日期的總小時數(shù).C#

        Sum hours from different formatted dates. C#(來自不同格式日期的總小時數(shù).C#)
      1. <legend id='Jnbq8'><style id='Jnbq8'><dir id='Jnbq8'><q id='Jnbq8'></q></dir></style></legend>
          <bdo id='Jnbq8'></bdo><ul id='Jnbq8'></ul>
          <i id='Jnbq8'><tr id='Jnbq8'><dt id='Jnbq8'><q id='Jnbq8'><span id='Jnbq8'><b id='Jnbq8'><form id='Jnbq8'><ins id='Jnbq8'></ins><ul id='Jnbq8'></ul><sub id='Jnbq8'></sub></form><legend id='Jnbq8'></legend><bdo id='Jnbq8'><pre id='Jnbq8'><center id='Jnbq8'></center></pre></bdo></b><th id='Jnbq8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Jnbq8'><tfoot id='Jnbq8'></tfoot><dl id='Jnbq8'><fieldset id='Jnbq8'></fieldset></dl></div>
            <tbody id='Jnbq8'></tbody>

          <small id='Jnbq8'></small><noframes id='Jnbq8'>

              • <tfoot id='Jnbq8'></tfoot>
                  本文介紹了來自不同格式日期的總小時數(shù).C#的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有問題.我需要在代碼中總結在辦公室工作的時間.我從 SQL 服務器獲得的日期沒問題,但我有不同的格式.例如:2019.09. 23. 14:54:232019.09.23 14:54:232019-09-23 14:54:23;我想總結工作時間.不分年份.示例如下:

                  I have a problem. I need to sum hours worked in an office in a code. The dates i get from SQL server thats no problem but i have different formats. For example: 2019. 09. 23. 14:54:23, 2019.09.23 14:54:23 or 2019-09-23 14:54:23; And i want to sum hours worked in result. No matter the year. Heres the example:

                  try
                          {
                  
                              string bet?lt = "SELECT * from munkaorak where";
                              if (cbTech.Text != "")
                              {
                                  bet?lt += " Munkaszam='" + cbMunka.Text + "' AND Részfolyamat='" + cbRész.Text + "' AND TechKod='" + cbTech.Text + "'";
                              }
                              else if (cbRész.Text != "")
                              {
                                  bet?lt += " Munkaszam='" + cbMunka.Text + "' AND Részfolyamat='" + cbRész.Text + "'";
                              }
                              else if(cbMunka.Text !="")
                              {
                                  bet?lt += " Munkaszam='" + cbMunka.Text + "'";
                              }
                              bet?lt += " order by ID DESC";
                              MySqlCommand name = new MySqlCommand(bet?lt, kapcsolat);
                              kapcsolat.Open();
                              olvasó = name.ExecuteReader();
                              int ?sszora = 0;
                  
                              if (olvasó.HasRows)
                              {
                                  while (olvasó.Read())
                                  {
                                      if (olvasó.GetString(7) != "Befejezés: ")
                                      {
                                          string[] aha = olvasó.GetString(6).Split(' ');
                                          string kezdes = aha[4];
                                          string[] kezd = kezdes.Split(':');
                                          int kezdoido = Convert.ToInt32(kezd[0]) * 60 * 60 + Convert.ToInt32(kezd[1]) * 60 + Convert.ToInt32(kezd[2]);
                  
                                          int befejezoido = 0;
                                          string aha22 = "";
                                          if (olvasó.GetString(7).IndexOf('-') >= 0)
                                          {
                                              string[] aha2 = olvasó.GetString(7).Split(' ');
                                              string befejezes = aha2[1];
                                              string[] bef = befejezes.Split(':');
                                              aha22 = aha2[0].Split('-')[2];
                                              befejezoido = Convert.ToInt32(bef[0]) * 60 * 60 + Convert.ToInt32(bef[1]) * 60 + Convert.ToInt32(bef[2]);
                                          }
                                          else
                                          {
                                              string[] aha2 = olvasó.GetString(7).Split(' ');
                                              string befejezes = aha2[4];
                                              string[] bef = befejezes.Split(':');
                                              aha22 = aha2[3];
                                              befejezoido = Convert.ToInt32(bef[0]) * 60 * 60 + Convert.ToInt32(bef[1]) * 60 + Convert.ToInt32(bef[2]);
                                          }                          
                  
                                          string dolgozott = "";
                                          if (aha[3].Replace(".", "") == aha22.Replace(".", ""))
                                          {
                                              dolgozott = mpbolora(befejezoido - kezdoido);
                                              ?sszora += befejezoido - kezdoido;
                                          }
                                          else
                                          {
                                              dolgozott = mpbolora((86400 - kezdoido) + befejezoido);
                                              ?sszora += (86400 - kezdoido) + befejezoido;
                                          }
                                          string validalo = "";
                                          try
                                          {
                                              string[] validal = olvasó.GetString(9).Split(' ');
                                              validalo = validal[0] + " " + validal[1] + " " + validal[2] + validal[3] + validal[4] + " " + validal[5];
                                          }
                                          catch
                                          {
                                              validalo = olvasó.GetString(9);
                                          }
                                          string munkafolyamat = olvasó.GetString(3) + "-" + olvasó.GetString(4) + "-" + olvasó.GetString(5);
                                          string[] sorok = { olvasó.GetString(2), dolgozott, olvasó.GetString(6).Replace("Kezdés: ", ""), olvasó.GetString(7).Replace("Befejezés: ", ""), olvasó.GetString(8), validalo, munkafolyamat };
                                          var lv = new ListViewItem(sorok);
                                          lvStat.Items.Add(lv);
                                      }
                  
                  
                                  }
                              }
                              else
                              {
                                  kapcsolat.Close();
                                  MessageBox.Show("Nincs adat!", "Figyelem");
                              }
                              kapcsolat.Close();
                              lbl?ssz.Text = "?sszesen ledolgozott órák: " + mpbolora(?sszora);
                          }
                          catch (Exception a)
                          {
                              MessageBox.Show(a.Message);
                              kapcsolat.Close();
                          }
                          kapcsolat.Close();
                  

                  它可以工作,但是當出現(xiàn)不同的格式時,由于-"或空格而無法正常工作.請幫忙!

                  It worked but when different formats appeared its not working because '-' or spaces. Please help!

                  推薦答案

                  C#中,提供了一堆方法可以將包含多種格式的日期時間的字符串轉換成統(tǒng)一的日期時間 對象.這些方法可以識別相當多的標準日期時間格式,如果您的格式與它們不同,您甚至可以提供自己的.

                  In C#, there is a bunch of methods provided to convert strings that contain date times in many formats into a unified DateTime object. These methods can recognize quite a few standard date time formats, and if yours differ from them, you can even provide your own.

                  • DateTime.Parse() - 將字符串轉換為 DateTime 對象.如果操作失敗,則會拋出異常.
                  • DateTime.TryParse() - 僅在可能的情況下將字符串轉換為 DateTime 對象.成功返回true,失敗返回false.
                  • DateTime.TryParseExact() - 將指定格式的字符串轉換為 DateTime 對象.如果成功則返回 true,否則返回 false.
                  • DateTime.Parse() - Converts a string to a DateTime object. If operation fails, it'll thrown an exception.
                  • DateTime.TryParse() - Converts a string to a DateTime object only if possible. Returns true if successful, and false if it fails.
                  • DateTime.TryParseExact() - Converts a string that is in the specified format into a DateTime object. Returns true if successful, and false otherwise.

                  在您的情況下,您可以使用 DateTime.TryParse() (推薦使用 DateTime.Parse() 除非您絕對確定格式是正確)像這樣:

                  In your case, you can use DateTime.TryParse() (which is recommended over simply using DateTime.Parse() unless you're absolutely sure the format is correct) like so:

                  var dtStr1 = " 2019. 09. 23. 14:54:23";
                  var dtStr2 = "2019.09.23 14:54:23";
                  var dtStr3 = "2019-09-23 14:54:23";
                  
                  DateTime.TryParse(dtStr1, out DateTime dt1);
                  DateTime.TryParse(dtStr2, out DateTime dt2);
                  DateTime.TryParse(dtStr3, out DateTime dt3);
                  

                  一旦轉換為 DateTime 對象,它就不再具有與之關聯(lián)的格式.它是一個結構,因此只有成員變量和方法.因此,要計算總小時數(shù)等,您可以使用提供的方法.

                  Once converted to a DateTime object, it no longer has a format associated with it. It's a structure, and hence only has member variables and methods. So to calculate total hours etc. you can use provided methods.

                  假設您想計算一天工作開始和結束之間的時間.您可以將它們轉換為 DateTime 對象,然后從其他對象中減去一個,這將給您一個 TimeSpam 對象.

                  Say you want to calculate time between day's work start and end. You can convert those into DateTime objects, then subtract one from the others which will give you a TimeSpam object.

                  var dtStrStart = "2019.09.23 08:23:12";
                  var dtStrEnd = "2019.09.23 16:17:28";
                  
                  DateTime.TryParse(dtStrStart, out DateTime dtStart);
                  DateTime.TryParse(dtStrEnd, out DateTime dtEnd);
                  
                  var diff = dtEnd - dtStart;
                  

                  現(xiàn)在,TimeSpan 對象,也就是這里的 diff,將為您提供一系列不同的屬性,以小時、分鐘等為單位.

                  Now the TimeSpan object, which is diff here, will give you a bunch of properties with difference in hours, minutes etc.

                  TimeSpan.DaysTimeSpan.Minutes 等會以天、分鐘等形式為您提供時間.

                  The TimeSpan.Days, TimeSpan.Minutes etc will give you the time in days, minutes etc.

                  Console.WriteLine(diff.Days);
                  Console.WriteLine(diff.Hours);
                  Console.WriteLine(diff.Minutes);
                  Console.WriteLine(diff.Seconds);
                  Console.WriteLine(diff.Milliseconds);
                  

                  輸出:

                  0

                  7

                  54

                  16

                  0

                  TimeSpan.TotalMinutes 等將為您提供相應單位的整個時間段.

                  The TimeSpan.TotalMinutes etc will give you the entire time period in respective units.

                  Console.WriteLine(diff.TotalDays);
                  Console.WriteLine(diff.TotalHours);
                  Console.WriteLine(diff.TotalMinutes);
                  Console.WriteLine(diff.TotalSeconds);
                  Console.WriteLine(diff.TotalMilliseconds);
                  

                  輸出:

                  0.329351851851852

                  0.329351851851852

                  7.90444444444444

                  7.90444444444444

                  474.266666666667

                  474.266666666667

                  28456

                  28456000

                  相反,當您在數(shù)據(jù)庫中存儲數(shù)據(jù)時,您必須再次使用標準格式,例如 datetimedatetime2.建議您使用 datetime2,更多信息.

                  And conversely, when you're storing data in the database, you must again use a standard format, such as datetime or datetime2. It's advised you use datetime2, more info here.

                  這篇關于來自不同格式日期的總小時數(shù).C#的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 OnClick)
                  • <small id='2FIed'></small><noframes id='2FIed'>

                          <tbody id='2FIed'></tbody>

                        <tfoot id='2FIed'></tfoot>
                        <i id='2FIed'><tr id='2FIed'><dt id='2FIed'><q id='2FIed'><span id='2FIed'><b id='2FIed'><form id='2FIed'><ins id='2FIed'></ins><ul id='2FIed'></ul><sub id='2FIed'></sub></form><legend id='2FIed'></legend><bdo id='2FIed'><pre id='2FIed'><center id='2FIed'></center></pre></bdo></b><th id='2FIed'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2FIed'><tfoot id='2FIed'></tfoot><dl id='2FIed'><fieldset id='2FIed'></fieldset></dl></div>
                        • <bdo id='2FIed'></bdo><ul id='2FIed'></ul>

                            <legend id='2FIed'><style id='2FIed'><dir id='2FIed'><q id='2FIed'></q></dir></style></legend>
                            主站蜘蛛池模板: 国产精品亚洲第一区在线暖暖韩国 | 欧美日韩在线一区二区三区 | 精品在线一区二区 | 欧美精品在线免费 | 91精品国产自产在线老师啪 | 在线观看国产 | 国产精品视频网站 | 97国产一区二区 | 国产精品久久久久久久久 | 天天操天天天 | 国产精久久久久久久妇剪断 | 亚洲精品av在线 | 91精品免费视频 | 亚洲精品视频一区二区三区 | 精品少妇一区二区三区在线播放 | 黄a在线观看 | h在线看 | 精品亚洲一区二区 | 国产激情视频 | 成人亚洲 | 国产精品福利视频 | 国产欧美一区二区三区在线看 | 一区中文字幕 | 久久精品高清视频 | 日韩一区在线视频 | 国产在线精品一区二区三区 | 久久国产精品无码网站 | 一区二区高清在线观看 | 国产精品免费大片 | 影音先锋欧美资源 | 国产aⅴ爽av久久久久久久 | 黄色av免费 | 香蕉国产在线视频 | 欧美日韩在线一区二区 | 亚洲黄色一区二区三区 | 欧美在线一区视频 | 91中文字幕在线观看 | 国产农村妇女毛片精品久久麻豆 | 亚洲视频一区二区三区四区 | 久久国产精品视频 | 亚洲精品1区2区3区 91免费看片 |