zoukankan      html  css  js  c++  java
  • 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();

            }

        }

    }

     

  • 相关阅读:
    如何调试在OJ中的代码
    在linux命令行中调试在OJ上的c++代码
    jar包
    stanford core
    decode encode
    访问服务器,远程访问linux主机
    代码18
    删除列表中的元素
    if __name__ == '__main__'
    苹果要求全部新app以及版本号更新必须支持iOS 8 SDK和64-bit
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2563468.html
Copyright © 2011-2022 走看看