• [转帖]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* 如:上午

  • 相关阅读:
    VC++6.0在win8.1系统下运行失败的解决办法
    oracle赋值问题(将同一表中某一字段赋值给另外一个字段的语句)
    Myeclipse 2014破解教程
    关于js赋值给input解析
    java时间格式
    Idea报错Check $M2_HOME environment variable and mvn script match.
    新博客
    理解jquery的$.extend()、$.fn和$.fn.extend()
    在vs code中使用ftp-sync插件实现客户端与服务器端代码的同步
    js字符串倒序
  • 原文地址:https://www.cnblogs.com/Excellent/p/1266205.html
Copyright © 2020-2023  润新知