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

            }

        }

    }

     

  • 相关阅读:
    2020年. NET Core面试题
    java Context namespace element 'component-scan' and its parser class ComponentScanBeanDefinitionParser are only available on JDK 1.5 and higher 解决方法
    vue 淡入淡出组件
    java http的get、post、post json参数的方法
    vue 父子组件通讯案例
    Vue 生产环境解决跨域问题
    npm run ERR! code ELIFECYCLE
    Android Studio 生成apk 出现 :error_prone_annotations.jar (com.google.errorprone:error) 错误
    记忆解析者芜青【总集】
    LwIP应用开发笔记之十:LwIP带操作系统基本移植
  • 原文地址:https://www.cnblogs.com/quietwalk/p/2563468.html
Copyright © 2011-2022 走看看