• [转]RDLC报表格式化format表达式


    本文转自:http://www.cnblogs.com/samlin/archive/2012/04/17/FormatDateTime.html

    刚开始接触RDLC报表,觉得RDLC报表提供的格式化工具太少,不像Crystal Report一样那么多的API支持,用起来多少的灵活啊。

    由于RDLC报表中有相关的日期格式字段,因此自然而然的就需要对日期字段进行格式化了,搜索了一些文章都是在介绍

    FormatDateTime函数,其实用起来就发现FormatDateTime不是我要的料,这此先看看FormatDateTime的声明吧:

    Function FormatDateTime(    ByVal Expression As DateTime,    Optional ByVal NamedFormat As DateFormat = DateFormat.GeneralDate ) As String
    DateFormat是一个枚举,其值很少不太适合中国人制作报表的习惯,

    NamedFormat 参数具有下列设置:

    常量说明
    DateFormat.GeneralDate 显示日期和/或时间。如果有日期部分,则用短日期格式显示。如果有时间部分,则用长时间格式显示。如果二者都有,则两部分都显示。
    DateFormat.LongDate 使用计算机的区域设置中指定的长日期格式来显示日期。
    DateFormat.ShortDate 使用计算机的区域设置中指定的短日期格式来显示日期。
    DateFormat.LongTime 使用计算机区域设置中指定的时间格式来显示时间。
    DateFormat.ShortTime 使用 24 小时格式 (hh:mm) 显示时间。

    FormatDateTime(Fields!PlanStartDate.Value,DateFormat.ShortDate)

    Command Result
    FormatDateTime(Parameters!Date.Value,1) Tuesday, April 10, 2007
    FormatDateTime(Parameters!Date.Value,2) 4/10/2007
    FormatDateTime(Parameters!Date.Value,3) 12:00:00 AM
    FormatDateTime(Parameters!Date.Value,4) 00:00

    如果我想通过FormatDateTime将日期格式显示成“2012年4月”,那就很难了。

    解决方法

    The Format command and specify the exact format you require.

    好Format函数现已隆重出场了,因此他确实可以解决我的问题,而且使用习惯与DateTime.ToString()类似,非常简单:

    Command Result
    Format(Parameters!Date.Value,"dd-MM-yyyy") 10-04-2007
    Format(Parameters!Date.Value,"dd/MM/yyyy") 10/04/2007
    Format(Parameters!Date.Value,"MMM-dd-yyyy") Apr-10-2007
    Format(Parameters!Date.Value,"MMM-dd-yy") Apr-10-07
    转载请注明出处[http://samlin.cnblogs.com/
  • 相关阅读:
    leetcode1161 Maximum Level Sum of a Binary Tree
    leetcode1162 As Far from Land as Possible
    leetcode107 Binary Tree Level Order Traversal II
    leetcode100 Same Tree
    spring常用注解的使用
    内部bean和级联属性的用法
    spring中ref标签的用法
    spring的依赖注入
    spring中的bean标签详解
    spring中BeanFactory和ApplicationContext的区别
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3353466.html
Copyright © 2020-2023  润新知