简体   繁体   中英

How get Week day name in custom format using vb.net/C#

Using following code get the current Day Name of a computer

Dim CompCurrCult = Globalization.CultureInfo.CurrentCulture
Dim dayOfWeek As DayOfWeek = CompCurrCult .Calendar.GetDayOfWeek(Date.Today)

Result : dayofWeek = Monday

So my question is how to get the result like MON instead of Monday

Calendar.GetDayOfWeek method returns full day name of a DateTime which provided as a parameter and it's based on DayOfWeek enumeration.

You can use "ddd" format specifier to get abbreviated name of the day. For C#;

DateTime.Today.ToString("ddd", CultureInfo.InvariantCulture); //Mon

If you want to get it as MON , just call .ToUpper() method like;

DateTime.Today.ToString("ddd", CultureInfo.InvariantCulture).ToUpper(); // MON

使用子字符串函数

Dim DayName As String = UCase(dayOfWeek.ToString.Substring(0, 3))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM