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();

            }

        }

    }

     

  • 相关阅读:
    通过filebeat收集并通过elsaticsearch的pipeline功能解析nginx访问日志
    markdown blog Typora+minio+upic图床改造
    spark 使用shc 访问hbase超时问题解决办法
    定制logstash-output-kafka 添加额外事务参数
    《机器学习十讲》第八讲总结
    寒假学习日报(二十四)
    《机器学习十讲》第七讲总结
    寒假学习日报(二十三)
    《机器学习十讲》第六讲总结
    寒假学习日报(二十二)
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2563468.html
Copyright © 2011-2022 走看看