zoukankan      html  css  js  c++  java
  • [转]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/
  • 相关阅读:
    js秒换成天时分
    vuex
    匹配iPhoneX
    ASP 解析json
    WPF 实现多语言支持
    c# 用DotNetZip来解压/压缩文件
    WPF UI Close button
    VB 获取所有窗体菜单信息
    ASP/ASP.NET/VB6文件上传
    c# 上传图片到一个外链相册服务器
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3353466.html
Copyright © 2011-2022 走看看