• DateTimeHelper


    
    namespace ConsoleApplication
    {
        using System;
        using Microshaoft;
        public class Class1
        {
            static void Main(string[] args)
            {
                DateTime x = DateTime.Now;
                x = new DateTime(2008,1,1,13,1,1,1);
                string s = DateTimeHelper.Get_yyyyMMddHHmmss_String(x);
                Console.WriteLine(s);
                Console.WriteLine(DateTimeHelper.Parse_yyyyMMddHHmmss(s));
                Console.WriteLine(DateTimeHelper.Parse_MMddHHmmss(2008, s.Substring(4, 10)));
                x = DateTime.Now.AddSeconds(5);
                Console.WriteLine(DateTimeHelper.Get_yyyyMMddHHmmss_String(x));
                while ("q" != Console.ReadLine())
                {
                    Console.WriteLine(DateTimeHelper.SecondsDiffNow(x));
                    DateTime dt = DateTime.Now;
                    Console.WriteLine(DateTimeHelper.GetAlignSecondsDateTime(dt, 7 * 60));
                }
                Console.WriteLine(Environment.Version.ToString());
            }
        }
    }
    namespace Microshaoft
    {
        using System;
        using System.Globalization;
        public static class DateTimeHelper
        {
            public static bool IsVaildateTimestamp(DateTime timeStamp, int timeoutSeconds)
            {
                long l = SecondsDiffNow(timeStamp);
                return ((l > 0) && (l < timeoutSeconds));
            }
            public static long MillisecondsDiffNow(DateTime time)
            {
                long now = DateTime.Now.Ticks;
                long t = time.Ticks;
                return (t - now)/10000;
            }
            public static long SecondsDiffNow(DateTime time)
            {
                return MillisecondsDiffNow(time)/1000;
            }
            public static DateTime GetAlignSecondsDateTime(DateTime time, long alignSeconds)
            { 
                long ticks = time.Ticks;
                ticks -= ticks % (10000 * 1000 * alignSeconds);
                DateTime dt = new DateTime(ticks);
                return dt ;
            }
            public static string Get_MMddHHmmss_String(DateTime time)
            {
                return time.ToString("MMddHHmmss");
            }
            public static string Get_yyyyMMddHHmmss_String(DateTime time)
            {
                return time.ToString("yyyyMMddHHmmss");
            }
            public static string Get_yyyyMMdd_String(DateTime time)
            {
                return time.ToString("yyyyMMdd");
            }
            public static DateTime Parse_yyyyMMddHHmmss(string text)
            {
                DateTime time = DateTime.TryParseExact
                                    (
                                        text
                                        , "yyyyMMddHHmmss"
                                        , DateTimeFormatInfo.InvariantInfo
                                        , DateTimeStyles.None
                                        , out time
                                    ) ? time : DateTime.MinValue;
                return time;
            }
            public static DateTime Parse_MMddHHmmss(int year, string text)
            {
                return Parse_yyyyMMddHHmmss(year.ToString("0000") + text);
            }
        }
    }
    
    
  • 相关阅读:
    CGI与fastcgi
    【总结】手动配置LNMP环境之安装NMP
    yum方式安装的Apache目录详解和配置说明
    W. Mysql
    V. PHP
    U. Apache
    学习进度条博客16
    构建之法阅读笔记05
    构建之法阅读笔记04
    构建之法阅读笔记03
  • 原文地址:https://www.cnblogs.com/Microshaoft/p/1321770.html
Copyright © 2020-2023  润新知