zoukankan      html  css  js  c++  java
  • DateTime.ToString()方法的参数谈ASP.NET中时间格式的转换 dodo

     
    有时候我们要对时间进行转换,达到不同的显示效果 
    默认格式为:2005-6-6 14:33:34  
    如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢 
    我们要用到:DateTime.ToString的方法(String, IFormatProvider) 

    using System; 
    using System.Globalization; 
    String format="D"; 
    DateTime date=DataTime,Now; 
    Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo)); 
    结果输出 
    Thursday, June 16, 2005 

    参数format格式详细用法 
    格式字符 关联属性/说明  
    d ShortDatePattern  
    D LongDatePattern  
    f 完整日期和时间(长日期和短时间)  
    F FullDateTimePattern(长日期和长时间)  
    g 常规(短日期和短时间)  
    G 常规(短日期和长时间)  
    m、M MonthDayPattern  
    r、R RFC1123Pattern  
    s 使用当地时间的 SortableDateTimePattern(基于 ISO 8601)  
    t ShortTimePattern  
    T LongTimePattern  
    u UniversalSortableDateTimePattern 用于显示通用时间的格式  
    U 使用通用时间的完整日期和时间(长日期和长时间)  
    y、Y YearMonthPattern  
  • 相关阅读:
    Linux03__管理
    Linux02__常用命令
    Linux01__系统安装
    爬虫性能相关
    【转载】资源整合
    Continuous integration
    行业巨头的云计算冷数据存储应用和比较 2016-07-15
    win7中使用docker ——配置阿里云容器加速
    layui treeSelect插件的使用
    springboot 拦截器设置
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/467018.html
Copyright © 2011-2022 走看看