using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSMachine.WMS.Infrastructure.Extensions { public static class DateTimeExtension { /// /// 获取当日零点 /// /// /// public static DateTime GetTodayBegin(this DateTime dateTime) { DateTime timeNow = DateTime.Now; return new DateTime(timeNow.Year, timeNow.Month, timeNow.Day, 0, 0, 0); } /// /// 获取当日23点59分59秒 /// /// /// public static DateTime GetTodayEnd(this DateTime dateTime) { DateTime timeNow = DateTime.Now; return new DateTime(timeNow.Year, timeNow.Month, timeNow.Day, 23, 59, 59); } /// /// 将秒数转化为时分秒 /// /// /// public static string Sec_to_hms(int duration) { TimeSpan ts = new(0, 0, duration); string str = ""; if (ts.Hours > 0) { str = string.Format("{0:00}", ts.Hours) + ":" + string.Format("{0:00}", ts.Minutes) + ":" + string.Format("{0:00}", ts.Seconds); } if (ts.Hours == 0 && ts.Minutes > 0) { str = "00:" + string.Format("{0:00}", ts.Minutes) + ":" + string.Format("{0:00}", ts.Seconds); } if (ts.Hours == 0 && ts.Minutes == 0) { str = "00:00:" + string.Format("{0:00}", ts.Seconds); } return str; } /// /// 将秒数转换为分秒 /// /// /// public static string Sec_to_ms(int duration) { TimeSpan ts = new(0, 0, duration); string str = ""; if (ts.Hours == 0 && ts.Minutes > 0) { str = string.Format("{0:00}", ts.Minutes) + ":" + string.Format("{0:00}", ts.Seconds); } if (ts.Hours == 0 && ts.Minutes == 0) { str = "00:" + string.Format("{0:00}", ts.Seconds); } return str; } } }