zoukankan      html  css  js  c++  java
  • MVC日期和其它字符串格式化

    string.Format("{0:d}",System.DateTime.Now) 结果为:2009-3-20 (月份位置不是03)
    string.Format("{0:D}",System.DateTime.Now) 结果为:2009年3月20日
    string.Format("{0:f}",System.DateTime.Now) 结果为:2009年3月20日 15:37
    string.Format("{0:F}",System.DateTime.Now) 结果为:2009年3月20日 15:37:52
    string.Format("{0:g}",System.DateTime.Now) 结果为:2009-3-20 15:38
    string.Format("{0:G}",System.DateTime.Now) 结果为:2009-3-20 15:39:27
    string.Format("{0:m}",System.DateTime.Now) 结果为:3月20日
    string.Format("{0:t}",System.DateTime.Now) 结果为:15:41
    string.Format("{0:T}",System.DateTime.Now) 结果为:15:41:50
    ……
    格式字符串 输入 结果
    "{0:C}" 12345.6789 $12,345.68
    "{0:C}" -12345.6789 ($12,345.68)
    "{0:D}" 12345 12345
    "{0:D8}" 12345 00012345
    "{0:E}" 12345.6789 1234568E+004
    "{0:E10}" 12345.6789 1.2345678900E+004
    "{0:F}" 12345.6789 12345.68
    "{0:F0}" 12345.6789 12346
    "{0:G}" 12345.6789 12345.6789
    "{0:G7}" 123456789 1.234568E8
    "{0:N}" 12345.6789 12,345.68
    "{0:N4}" 123456789 123,456,789.0000
    "Total: {0:C}" 12345.6789 Total: $12345.68
    其常用的日期格式如下表所示:
    
    格式 说明 输出格式
    d 精简日期格式 MM/dd/yyyy
    D 详细日期格式 dddd, MMMM dd, yyyy
    f 完整格式 (long date + short time) dddd, MMMM dd, yyyy HH:mm
    F 完整日期时间格式 (long date + long time) dddd, MMMM dd, yyyy HH:mm:ss
    g 一般格式 (short date + short time) MM/dd/yyyy HH:mm
    G 一般格式 (short date + long time) MM/dd/yyyy HH:mm:ss
    m,M 月日格式 MMMM dd
    s 适中日期时间格式 yyyy-MM-dd HH:mm:ss
    t 精简时间格式 HH:mm
    T 详细时间格式 HH:mm:ss

    也可以在cshtml页面的js内使用方法:
     OrderDate = '@string.Format("{0:yyyy-MM-dd}",DateTime.Now)';
  • 相关阅读:
    SAP SD 模块面试题
    商品ATP check FM(获得可用库存和总库存)
    获得SO的凭证流
    SAP XI 常用事务代码
    ABAP 面试问题及答案(一)(转)
    ABAP 面试题(转)
    SAP XI 3.0考试大纲
    Enterprise System Applicaiton 试题
    Enterprise Portal 试题
    ABAP 100 道面试题
  • 原文地址:https://www.cnblogs.com/firstcsharp/p/6402166.html
Copyright © 2011-2022 走看看