• DateTimeConverter


     

      xmlns:Converters="clr-namespace:SBMI.rEHR.Utils.Converter"

       <Local:View.Resources>

            <Converters:DateTimeConverter x:Key="DateTimeConverter"/>

        </Local:View.Resources>

    Converter={StaticResource DateTimeConverter},ConverterParameter='DateTimeString'

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Globalization;

    using System.Windows.Data;

     

    /********************************************

     * quietwalk

     * 06/26/2012

     *

     * ******************************************/

     

    namespace SBMI.rEHR.Utils.Converter

    {

        /// <summary>

        /// Convert DateTime to: DateTimeString MM/dd/yyyy; DateString; TimeString

        /// </summary>

        public class DateTimeConverter : IValueConverter

        {

            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

            {

                if (value == null) return null;

     

                DateTime dt = System.Convert.ToDateTime(value);

                if (dt == null) return null;

     

                if (parameter != null)

                {

                    string strResult = string.Empty;

                    string param = parameter as string;

     

                    if (string.IsNullOrEmpty(param) == false)

                    {

                        if (param.ToLower() == "datetimestring")

                        {

                            strResult = dt.ToString("MM/dd/yyyy");

                        }

                        else if (param.ToLower() == "datestring")

                        {

                            //strResult = string.Format("{0:d}", dt);

                            strResult = dt.ToString("MM/dd/yyyy");

                        }

                        else if (param.ToLower() == "timestring")

                        {

                            strResult = string.Format("{0:T}", dt);

                        }

                        return strResult;

                    }

                }//if

     

                return null;

            }

     

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

            {

     

                throw new NotImplementedException();

            }

        }

    }

     

  • 相关阅读:
    用C#一次匹配HTML代码中A的链接和文字的方法
    去黑头的7个必胜秘方
    用C#写外挂或辅助工具必须要的WindowsAPI
    用C#把HTML内容转为UBB的方法
    Windows Server 2008 Standard, Enterprise, and Datacenter with Service Pack 2
    xmpp协议分析
    查看Win7的真实版本号方法
    什么是游戏NP?如何在NP下读写游戏内存及如何进入NP进程
    C#正则表达式扫盲 保证 10分钟入门 30分钟精通[绝对不可错过的文章]
    可扩展消息出席协议(XMPP):核心 RFC 3920
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2563468.html
Copyright © 2020-2023  润新知