预览模式: 普通 | 列表

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.

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 172

vb.net 日期时间格式转换(Format函数)

VB.net 中 取系统时间

Dim datestr As String = ""

datestr = Format(Now(), "yyyy/MM/dd H:mm:ss ffff")

用户定义的日期/时间格式(Format 函数)

下表显示可用于创建用户定义的日期/时间格式的字符。与 Visual Basic 的早期版本不同,这些格式字符区分大小写。

字符 说明

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 176

VB.net 文件读取、写入、追加操作

 

Imports System.IO

 

Dim PathUserData As String = Application.StartupPath & "\实操统计sql.txt"

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 154

 广告位