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

87 lines
2.3 KiB

using System;
using System.Collections.Generic;
using System.Text;
using Gm_WMS.DataAccess.DataService;
namespace Stone.DataService.Biz.BizPublic
{
public class ServerDateTime
{
public static DateTime GetDateTime()
{
try
{
LocalDBService db = new LocalDBService();
return (DateTime)db.Exec_DataSet("select getdate() as [date]").Tables[0].Rows[0][0];
}
catch
{
throw new Exception("»ñÈ¡·þÎñÆ÷ʱ¼äʧ°Ü£¡");
}
}
public static string GetDateTime(ServerDateTimeType dType)
{
DateTime sDataTime = GetDateTime();
string Result = "";
string year = sDataTime.Year.ToString();
string month = sDataTime.Month.ToString();
string day = sDataTime.Day.ToString();
string h = sDataTime.Hour.ToString();
string m = sDataTime.Minute.ToString();
string s = sDataTime.Second.ToString();
string mi = sDataTime.Millisecond.ToString();
if (month.Length == 1) month = "0" + month;
if (day.Length == 1) day = "0" + day;
if (h.Length == 1) h = "0" + h;
if (m.Length == 1) m = "0" + m;
if (s.Length == 1) s = "0" + s;
if (mi.Length == 1) mi = "00" + mi;
if (mi.Length == 2) mi = "0" + mi;
if (dType == ServerDateTimeType.DateTime)
{
Result = year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
}
if (dType == ServerDateTimeType.Date)
{
Result = year + "-" + month + "-" + day;
}
if (dType == ServerDateTimeType.Time)
{
Result = h + ":" + m + ":" + s;
}
if (dType == ServerDateTimeType.Batch)
{
Result = year.Substring(2, 2) + month + day;
}
if (dType == ServerDateTimeType.BillNo)
{
Result = year + month + day + h + m + s + mi;
}
return Result;
}
}
/// <summary>
/// ·þÎñÆ÷ÈÕÆÚʱ¼ä¸ñʽÀà±ð
/// </summary>
public enum ServerDateTimeType
{
DateTime = 1,
Date = 2,
Time = 3,
Batch = 4,
BillNo = 5
}
}