1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace LYFZ
- {
- /// <summary>
- /// 服务器时间类
- /// </summary>
- public class SDateTime
- {
- public SDateTime()
- {
- }
- static bool isAutomaticUpdate = false;
- /// <summary>
- /// 是否有程序在自动更新本时间类
- /// </summary>
- public static bool IsAutomaticUpdate
- {
- get { return SDateTime.isAutomaticUpdate; }
- set { SDateTime.isAutomaticUpdate = value; }
- }
- static DateTime _now = DateTime.Now;
- /// <summary>
- /// 服务器当前时间
- /// </summary>
- public static DateTime Now
- {
- get
- {
- if (IsAutomaticUpdate && SDateTime._now != null)
- {
- return SDateTime._now;
- }
- else
- {
- return DateTime.Now;
- }
- }
- // set { SDateTime._now = value; }
- }
- /// <summary>
- /// 服务器当前时间转Long
- /// </summary>
- public static long NowToLong
- {
- get {
- return SDateTime.DateTimeToLong(SDateTime.Now);
- }
- }
- /// <summary>
- /// 设置服务器端时间
- /// </summary>
- /// <param name="t"></param>
- public static void SetNow(DateTime t)
- {
- SDateTime._now = t;
- }
- /// <summary>
- /// 转 20161003160647 格式long为时间类型
- /// </summary>
- /// <param name="dtLong">20161003160647 格式long</param>
- /// <returns></returns>
- public static DateTime ConvertLongToDateTime(long dtLong)
- {
- return LYFZ.WinAPI.CustomPublicMethod.StringToDateTime(dtLong);
- }
- /// <summary>
- /// 转DateTime 为 yyyyMMddHHmmss 格式的 long
- /// </summary>
- /// <param name="t"></param>
- /// <returns></returns>
- public static long DateTimeToLong(DateTime t)
- {
- return LYFZ.WinAPI.CustomPublicMethod.DateTimeToLong(t);
- }
- }
- }
|