在vb.net中以dd / mm / yyyy格式显示日期 [英] Display date in dd/mm/yyyy format in vb.net

查看:129
本文介绍了在vb.net中以dd / mm / yyyy格式显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以09/07/2013格式显示日期,而不是13年7月9日。

I want to display date in 09/07/2013 format instead of 09-jul-13.

Dim dt As Date = Date.Today

MsgBox(dt)


推荐答案

首先,大写的MM是月份,小写的mm是分钟。

First, uppercase MM are months and lowercase mm are minutes.

您必须传递 CultureInfo.InvariantCulture ToString 以确保使用 / 作为日期分隔符,因为通常会用当前的区域性替换它。日期分隔符:

You have to pass CultureInfo.InvariantCulture to ToString to ensure that / as date separator is used since it would normally be replaced with the current culture's date separator:

MsgBox(dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture))

另一种选择是通过将/嵌入':

Another option is to escape that custom format specifier by embedding the / within ':

dt.ToString("dd'/'MM'/'yyyy")

MSDN : /自定义格式说明符

MSDN: The "/" Custom Format Specifier:


T /自定义格式说明符表示日期分隔符,
用于区分年,月和日。适当的
本地化日期分隔符是从$ 或指定的

DateTimeFormatInfo.DateSeparator 属性中检索的。 文化

这篇关于在vb.net中以dd / mm / yyyy格式显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆