You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB
C#

7 months ago
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ibk.KPI.Common
{
class DateUtils
{
// 获取当前时间字符串(格式自己传入,如:"yyyy-MM-dd HH:mm:ss")
public string CurrentTimeStr(string format)
{
return DateTime.Now.ToString(format, DateTimeFormatInfo.InvariantInfo);
}
// DateTime 转成时间戳(默认是毫秒值)
public long GetTimeStamp(DateTime dt, bool bflag)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
TimeSpan ts = dt - startTime;
long ret = 0;
if (bflag)
// 返回秒
ret = Convert.ToInt64(ts.TotalSeconds);
else
// 返回毫秒
ret = Convert.ToInt64(ts.TotalMilliseconds);
return ret;
}
// 指定格式的字符串(如yyyyMMddHHmmss)转成DateTime(格式是{2021/9/11 14:04:23})
public DateTime StrToDateTime(string str, string format)
{
return DateTime.ParseExact(str, format, System.Globalization.CultureInfo.CurrentCulture);
}
public static void Main(string[] args)
{
Console.WriteLine("输入正三角形的边长:");
}
}
}