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.
 
 
 
 

135 lines
3.7 KiB

using System;
using System.Collections.Generic;
using System.Text;
namespace Stone.Common
{
public class MyDateTime
{
public static DateTime GetServerDateTime()
{
Gm_WMS.DataAccess.DataService.LocalDBService db = new Gm_WMS.DataAccess.DataService.LocalDBService();
return Convert.ToDateTime(db.Exec_DataSet("select getdate()").Tables[0].Rows[0][0]);
}
public static string Format(DateTime sDataTime, MyDateTimeType dType)
{
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 == MyDateTimeType.DateTime)
{
Result = year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
}
if (dType == MyDateTimeType.DateTime1)
{
Result = month + "." + day + "." + year;
}
if (dType == MyDateTimeType.DateTime2)
{
Result = month + "." + day + "." + year + " " + h + "." + m;
}
if (dType == MyDateTimeType.DateTime3)
{
Result = year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s;
}
if (dType == MyDateTimeType.Date)
{
Result = year + "-" + month + "-" + day;
}
if (dType == MyDateTimeType.Date2)
{
Result = year.Substring(2, 2) + month + day;
}
if (dType == MyDateTimeType.Date3)
{
Result = sDataTime.ToString("yy/MM/dd");
}
if (dType == MyDateTimeType.Time)
{
Result = h + ":" + m + ":" + s;
}
if (dType == MyDateTimeType.Time1)
{
Result = h + "-" + m + "-" + s;
}
if (dType == MyDateTimeType.Time2)
{
Result = h + m + "";
}
if (dType == MyDateTimeType.Time3)
{
Result = h + ":" + m + "";
}
if (dType == MyDateTimeType.Batch)
{
Result = year.Substring(2, 2) + month + day;
}
if (dType == MyDateTimeType.BillNo)
{
Result = year + month + day + h + m + s + mi;
}
if (dType == MyDateTimeType.YearMonth)
{
Result = year + month;
}
return Result;
}
public static string Format(MyDateTimeType dType)
{
DateTime d = GetServerDateTime();
return Format(d, dType);
}
}
public enum MyDateTimeType
{
DateTime = 1,
Date = 2,
Date2 = 6,
Date3 = 13,
Time = 3,
Time1 = 10,
Time2 = 11,
Time3 = 12, //10:02
Batch = 4,
BillNo = 5,
DateTime1 = 6, //01.02.2014
DateTime2 = 7, //01.02.2014 06.07s
DateTime3 = 9, //2014-01-20 18:50
YearMonth = 8,
}
}