VB 6.0 - 格式化日期 [英] VB 6.0 - Formatting Date

查看:54
本文介绍了VB 6.0 - 格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个程序,我正在努力使其更有效率.其中有一些文本框需要用户输入.当所有必需的信息都在时,将在另一个多行文本框中生成报告.生成的报告中显示的日期采用dd/MM/yy"格式非常重要.我已经在下面使用了这个代码:

I've created a program and I'm trying to make it a lot more efficient. There are textboxes in it requiring entries from the user. When all the required information is in, a report is being generated in another multiline textbox. It is really important that the Date shown in the generated report is of this format "dd/MM/yy". I've already used this code below :

Dim a as String
a = Format(Textbox1.text, "dd/MM/yy")

但是,这样做的唯一作用是,当有人使用dd-MM-yy"这种格式输入日期时,它会将其转换为我想要的日期.但是当有人使用."(dd.MM.yy) 甚至 " "(dd MM yy) 它不会转换它.有没有办法让我从输入的日期中提取字符,不管它是怎么写的,然后把它转换成我想要的?

However the only thing this does is that when someone types the date with this format "dd-MM-yy" it converts it to the one one I want. But when someone uses "." (dd.MM.yy) or even " "(dd MM yy) it doesn't convert it. Is there a way for me to extract the characters from the entried date no matter how it is being written and convert it to the one I want ?

推荐答案

右键单击工具箱,选择 Components... 并向下滚动到 Microsoft Windows Common Controls-2 6.0 (SP6)(或类似的东西).这将向工具箱添加更多控件.您要使用的控件是 DTPicker 控件.

Right click on the toolbox, select Components... and scroll down to Microsoft Windows Common Controls-2 6.0 (SP6) (or something similar). This will add more controls to the toolbox. The control you want to use is the DTPicker control.

要获取所需格式的日期,请使用

To get the date in your required format, use

Dim a As String
a = Format(DTPicker1.Value, "dd/MM/yy")

这篇关于VB 6.0 - 格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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