日期格式yyyy / mm / dd [英] Date Format yyyy/mm/dd
本文介绍了日期格式yyyy / mm / dd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在整个VB.NET应用程序中设置默认日期格式 yyyy / mm / dd
?
我使用了这两种方式但没有成功
How to set the default date format yyyy/mm/dd
in the whole VB.NET app?
I used these two ways but without success
Protected Sub Application_BeginRequest(ByVal sender As [Object], ByVal e As EventArgs)
Dim newCulture As CultureInfo = DirectCast(System.Threading.Thread.CurrentThread.CurrentCulture.Clone(), CultureInfo)
newCulture.DateTimeFormat.ShortDatePattern = "yyyy/MM/dd"
newCulture.DateTimeFormat.DateSeparator = "/"
Thread.CurrentThread.CurrentCulture = newCulture
---------------------------------------------------------------------------------
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
推荐答案
您可以为日期时间编写扩展方法,并在必要时使用它,如下所示:
you can write an extension method for the datetime and use it where necessary as in the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test_DatetimeFormat
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.Today.ToMyFormat());
}
}
static class Utils
{
public static string ToMyFormat(this DateTime dt)
{
return dt.ToString("yyyy/MM/dd");
}
}
}
这篇关于日期格式yyyy / mm / dd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文