zoukankan      html  css  js  c++  java
  • [转帖]asp.net 日期操作

    1、DateTime 数字型
    System.DateTime currentTime=new System.DateTime();

    1.1 取当前年月日时分秒
    currentTime=System.DateTime.Now;

    1.2 取当前年
    int 年=currentTime.Year;

    1.3 取当前月
    int 月=currentTime.Month;

    1.4 取当前日
    int 日=currentTime.Day;

    1.5 取当前时
    int 时=currentTime.Hour;

    1.6 取当前分
    int 分=currentTime.Minute;

    1.7 取当前秒
    int 秒=currentTime.Second;

    1.8 取当前毫秒
    int 毫秒=currentTime.Millisecond;
    (变量可用中文)

    1.9 取中文日期显示——年月日时分
    string strY=currentTime.ToString("f"); //不显示秒

    1.10 取中文日期显示_年月
    string strYM=currentTime.ToString("y");

    1.11 取中文日期显示_月日
    string strMD=currentTime.ToString("m");

    1.12 取中文年月日
    string strYMD=currentTime.ToString("D");

    1.13 取当前时分,格式为:14:24
    string strT=currentTime.ToString("t");

    1.14 取当前时间,格式为:2003-09-23T14:46:48
    string strT=currentTime.ToString("s");

    1.15 取当前时间,格式为:2003-09-23 14:48:30Z
    string strT=currentTime.ToString("u");

    1.16 取当前时间,格式为:2003-09-23 14:48
    string strT=currentTime.ToString("g");

    1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT
    string strT=currentTime.ToString("r");

    1.18获得当前时间 n 天后的日期时间
    DateTime newDay = DateTime.Now.AddDays(100)

    d MM/dd/yyyy 如(2001-3-27) 
        D dddd, MMMM dd, yyyy 如(2001年3月27日) 
        f dddd, MMMM dd, yyyy HH:mm 如(2001年3月27日 0:00) 
        F dddd, MMMM dd, yyyy HH:mm:ss 如(2001年3月27日 0:00:00) 
        g MM/dd/yyyy HH:mm 如(2001-3-27 0:00) 
        G MM/dd/yyyy HH:mm:ss 如(2001-3-27 0:00:00) 
        m, M MMMM dd 如(三月 27) 
        r, R ddd, dd MMM yyyy HH’:’mm’:’ss ’GMT’ 如(Mon, 26 Mar 2001 16:00:00 GMT) 
        s yyyy-MM-dd HH:mm:ss 好像不能使用 
        t HH:mm 如(0:00) 
        T HH:mm:ss 如(0:00:00) 
        u yyyy-MM-dd HH:mm:ss 如(2001-03-26 16:00:00Z) 
        U dddd, MMMM dd, yyyy HH:mm:ss 如(2001年3月26日 16:00:00) 
        y, Y MMMM, yyyy 如(2001年3月) 
        
        自定义格式列表Format Pattern Description 
        d 如:2001-3-27 
        dd 如:27 
        ddd 如:星期一 
        dddd 如:星期一(全名) 
        M 如:三月 27 
        MM 如:03 
        MMM 如:三月 
        MMMM 如:三月(全称) 
        y 如:2001年3月 
        yy 如:01 
        yyyy 如:2001 
        gg 如:A.D. 
        hh, hh* 如:12 
        HH, HH* 如:00 
        m 如:三月 27 
        mm, mm* 如:00(分钟) 
        s 如:2001-03-27T00:00:00 
        ss, ss* 如:00(秒) 
        t 如:0:00 
        tt, tt* 如:上午

  • 相关阅读:
    bzoj 3709: [PA2014]Bohater【贪心】
    bzoj 3714: [PA2014]Kuglarz【最小生成树】
    bzoj 2216: [Poi2011]Lightning Conductor【决策单调性dp+分治】
    bzoj 2087: [Poi2010]Sheep【凸包+极角排序+dp】
    bzoj 3830: [Poi2014]Freight【dp】
    bzoj 3930: [CQOI2015]选数【快速幂+容斥】
    bzoj 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式【后缀自动机】
    bzoj 1614: [Usaco2007 Jan]Telephone Lines架设电话线【二分+spfa】
    bzoj 1640||1692: [Usaco2007 Dec]队列变换【后缀数组】
    bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛【Floyd】
  • 原文地址:https://www.cnblogs.com/Excellent/p/1266205.html
Copyright © 2011-2022 走看看