Click here to Skip to main content
15,894,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set the default date format yyyy/mm/dd in the whole VB.NET app?

I used these two ways but without success
VB
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")
Posted
Updated 9-Feb-14 0:18am
v2

1 solution

you can write an extension method for the datetime and use it where necessary as in the following:

C#
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");
        }
    }
}
 
Share this answer
 
Comments
Eman Ayad 17-Feb-14 6:24am    
Thanks, but I need to make it the default format for the project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900