c# - 如何使用 C# 使 datetime.now 返回英国格式的日期

标签 c# datetime

我希望 datetime.now 返回英国格式的日期时间对象。它在我的本地计算机上执行此操作,但当我将代码上传到服务器时,它以美国格式执行

最佳答案

DateTime 没有任何与之关联的格式。格式化只是为了演示。你可以这样做:

string formattedDate = DateTime.Now.ToString(CultureInfo.CreateSpecificCulture("en-GB"));

或者提供特定/自定义格式,例如:

string formattedDate = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss", 
                                       CultureInfo.InvariantCulture);

关于c# - 如何使用 C# 使 datetime.now 返回英国格式的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28864147/

相关文章:

python - 使用 pandas : TypeError: <class 'list' > is not convertible to datetime 将字符串转换为日期时间

c# - 使用 LINQ 创建 JSON

c# - 列表框selectedItem问题

ruby - 在 Rails 中格式化 float 时间

PHP 使用 DatePeriod 创建带休息时间的时间段

mysql - 检查是否超过 30 分钟

php - 从日期中恰好删除一个月

c# - 如何保护我的查询 : I get The SqlParameter is already contained by another SqlParameterCollection

c# - ASP.NET 中的 die() 或 exit() 功能

c# - 两个列表的 linq 并集