我已将系统日期格式更改为 Faeroese。
我想根据customCulture将DateTime转换为String,G格式(日期和时间的组合)
检查下面的代码。
namespace TestDateConvertion
{
class Program
{
static void Main(string[] args)
{
object value = new DateTime(2003,12,23,6,22,30);
DateTime dateTimeValue = (DateTime)value;
CultureInfo customCulture = MySettings.getCustomCulture();
//for getting custom culture in my app
//in custom culture i have changed shortDateFormat according to the user preference.
//value in shortDateFormat = dd/MM/yyyy
string result = string.Format(customCulture, "{0:G}", result);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
但我根据系统 DateTime 而不是用户在 customCulture 中给定格式得到带有分隔符的输出,
我什至没有发现任何重载string.Format()
或DateTime.ToString()
执行此操作的方法。
如果我通过 CultureInfo.InvariantCulture 那么我无法获得 G 格式的输出。