VB.Net转换时间/日期值为字符串的方法

Working with date and time values often requires an ability to convert these values into string values in a particular format. In this article, I'll look at a simple way of converting these values into formatted strings.
Working with standard format strings
You can convert a Date/Time value into a string by overloading a version of the ToString method, which accepts a format string.
There are two types of Date/Time format strings: standard and custom. The standard format strings use one of the predefined formats and are specified by a letter corresponding to a particular format. When converting a Date/Time value to a string, the letter specifying one of the standard formats is used to refer to a particular format specifier. Here's a list of the standard date format specifiers:
  • d: short date
  • D: long date
  • t: short time
  • T: long time
  • f: full Date/Time with short time
  • F: full Date/Time with long time
  • g: general Date/Time with short time
  • G: general Date/Time with long time
  • M or m: month day
  • R or r: RFC1123
  • s: sortable Date/Time that conforms to ISO 8601
  • u: universal sortable Date/Time
  • U: full Date/Time with long time. (This format is the same as F, but it uses universal GMT time.)
  • Y or y: year month
Control Panel settings
The settings in the Control Panel's Regional and Language Options section influence the result you get when formatting a Date/Time value. The settings are used to initialize the DateTimeFormatInfo object, which is associated with the current thread culture and provides the values that control the formatting.

Dim dateTimeInfo as DateTime = DateTime.Now MessageBox.Show (dateTimeInfo) Dim strMonth as String = dateTimeInfo.ToString("m") MessageBox.Show(strMonth)

The code defines the DateTime variable dateTimeInfo and sets its value to the current Date/Time. Then, I define the String variable strMonth and convert the value of dateTimeInfo into a String in a Month format.



上一篇: vb.net 日期时间格式转换(Format函数)
下一篇: nginx隐藏php版本信息X-Powered-By
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: vb.net
相关日志:
评论: 0 | 引用: 0 | 查看次数: 172
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭

 广告位

↑返回顶部↑