using System;
using System.Windows.Data;
namespace WpfApplication1
{
class DateTimeConverter1 : IValueConverter
{
// Convertは問題なし。
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// DateTime型 -> HH:ss (時刻だけを表示する)
var d = System.Convert.ToDateTime(value);
return d.ToString("HH:ss");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// valueにはテキストボックスに入力したstring型の時刻(HH:mm)が入っている。
// この書き方だと結局 Today になってしまう。
DateTime d = System.Convert.ToDateTime(value.ToString());
return d;
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uV2luZG93cy5EYXRhOwoKbmFtZXNwYWNlIFdwZkFwcGxpY2F0aW9uMQp7CiAgICBjbGFzcyBEYXRlVGltZUNvbnZlcnRlcjEgOiBJVmFsdWVDb252ZXJ0ZXIKICAgIHsKICAgICAgICAvLyBDb252ZXJ044Gv5ZWP6aGM44Gq44GX44CCCiAgICAgICAgcHVibGljIG9iamVjdCBDb252ZXJ0KG9iamVjdCB2YWx1ZSwgVHlwZSB0YXJnZXRUeXBlLCBvYmplY3QgcGFyYW1ldGVyLCBTeXN0ZW0uR2xvYmFsaXphdGlvbi5DdWx0dXJlSW5mbyBjdWx0dXJlKQogICAgICAgIHsKICAgICAgICAgICAgLy8gRGF0ZVRpbWXlnosgLT4gSEg6c3MgKOaZguWIu+OBoOOBkeOCkuihqOekuuOBmeOCiykKICAgICAgICAgICAgdmFyIGQgPSBTeXN0ZW0uQ29udmVydC5Ub0RhdGVUaW1lKHZhbHVlKTsKICAgICAgICAgICAgcmV0dXJuIGQuVG9TdHJpbmcoIkhIOnNzIik7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgb2JqZWN0IENvbnZlcnRCYWNrKG9iamVjdCB2YWx1ZSwgVHlwZSB0YXJnZXRUeXBlLCBvYmplY3QgcGFyYW1ldGVyLCBTeXN0ZW0uR2xvYmFsaXphdGlvbi5DdWx0dXJlSW5mbyBjdW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