現在保存されている米国の形式ではなく、英国の形式で日付を返したいです。
したがって、クラス内の値にゲッターとセッターを追加することにしました。
ただし、ゲッターとセッターを配置してコードを実行すると、ページの読み込みに失敗します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
// Globalisation for converting dates from American to British format
using System.Globalization;
/// <summary>
/// Class to hold the summary of an order take from database TOEHEAD
/// </summary>
public class OrderSummary
{
public string order_number { get; set; }
public string order_date
{
get
{
try
{
string ukDateTimeFormat = Convert.ToString(DateTime.Parse(this.order_date, CultureInfo.CreateSpecificCulture("en-US")));
return ukDateTimeFormat;
}
catch (FormatException e)
{
return "Error";
}
}
set
{
this.order_date = value;
}
}
public string order_total { get; set; }
public OrderSummary()
{
}
}
このコードを関数に入れてそのように返すと、正常に動作します。
何か間違ってフォーマットしましたか?