1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MECF.Framework.Common.Utilities
- {
- public class DateTimeUtil
- {
- public static int GetSecond(string timeString)
- {
- if (string.IsNullOrEmpty(timeString)) return 0;
- if (TimeSpan.TryParse(timeString, out TimeSpan timeSpan))
- {
- // 获取总秒数(包括小数部分)
- double totalSeconds = timeSpan.TotalSeconds;
- // 将总秒数转换为整数秒数
- int integerSeconds = Convert.ToInt32(totalSeconds);
- return integerSeconds;
- }
- return 0;
- }
- public static int GetSecond(float number)
- {
- if (number.ToString().Contains('.'))
- {
- var strs = number.ToString().Split('.').Select(a => int.Parse(a)).ToList();
- return strs[0] * 3600 + strs[1] * 60;
- }
- else
- {
- return (int)number * 3600;
- }
- }
- public static string SecondToHHmmss(string value)
- {
- if (value == null)
- return "";
- if (float.TryParse(value, out float floatResult))
- {
- var secondAll = Math.Round(floatResult, 1, MidpointRounding.AwayFromZero);
- // 将总秒数转换为时间跨度
- TimeSpan timeSpan = TimeSpan.FromSeconds(secondAll);
- // 格式化为 HH:mm:ss
- string formattedTime = $"{timeSpan.Hours:D2}:{timeSpan.Minutes:D2}:{timeSpan.Seconds:D2}";
- return formattedTime;
- }
- return "00:00:00";
- }
- public static void ConvertSecondsToHoursAndMinutes(int totalSeconds, out int hours, out int minutes)
- {
- hours = totalSeconds / 3600;
- int remainingSeconds = totalSeconds % 3600;
- minutes = remainingSeconds / 60;
- }
- }
- }
|