How to Custom Date Format in TSWA

本文介绍了解决Team System Web Access (TSWA) 中工作项自定义日期格式显示不正确的方法。通过手动格式化及定时刷新,确保了日期始终以预期格式展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As we know, once you set the Format and CustomFormat of DateTimeControla in WorkItemType like

<Control FieldName="FinishedDate" Type="DateTimeControl" Label="Finished Date:" LabelPosition="Left" Format="Custom" CustomFormat="yyyy-MM-dd" />

The value of Format could be

{
    Custom = 8,
    Long = 1,
    Short = 2,
    Time = 4
} When you choose Custom, the control will use the CustomFormat.

 

Team Explorer will display the date in correct format, but TSWA will not.The reason why TSWA still show as a long time is that it does not format the value of the textbox when page loaded, so we need to format it manually.

Furthermore, when you save the workitem, the page will perform a asynchronous postback. This cause the textbox display the date in long time format again. The best way is to subscribe the onSuccess event and format the value. But I did not find such an event to subscribe, so I format the value occasionally. The workaround is as below.

Add following code to the end of  C:\Program Files\Microsoft Visual Studio 2008 Team System Web Access\Web\UI\Controls\WorkItems\EditWorkItem.ascx

 

<script type="text/javascript">


    window.onload = init;

    function init() {
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            var input = inputs[i];
            if (input.className == "DTPInput") {
                var d = eval("_" + input.id.replace("_txt", ""));
                d.init();

                var date = new Date(d.m_input.value);
                if (date > 0) {
                    d.m_input.value = DateUtility.format(new Date(d.m_input.value), d.m_config, d.m_config.Format);
                }

                setInterval("FormatDate('" + "_" + input.id.replace("_txt", "") + "')", 1000);
                
            }
        }
    }


    function FormatDate(id) {


        var d = eval(id);
        
        var date=new Date(d.m_input.value);
        if (date >0) {
            d.m_input.value = DateUtility.format(new Date(d.m_input.value), d.m_config, d.m_config.Format);
        }
    }

</script>

转载于:https://www.cnblogs.com/Ruiz/archive/2009/10/19/1586047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值