first commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取当日零点
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime GetTodayBegin(this DateTime dateTime)
|
||||
{
|
||||
DateTime timeNow = DateTime.Now;
|
||||
|
||||
return new DateTime(timeNow.Year, timeNow.Month, timeNow.Day, 0, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当日23点59分59秒
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime GetTodayEnd(this DateTime dateTime)
|
||||
{
|
||||
DateTime timeNow = DateTime.Now;
|
||||
|
||||
return new DateTime(timeNow.Year, timeNow.Month, timeNow.Day, 23, 59, 59);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将秒数转化为时分秒
|
||||
/// </summary>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将秒数转换为分秒
|
||||
/// </summary>
|
||||
/// <param name="duration"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user