代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
VB.Net
】
获得当前的日期和时间
作者:
/ 发布于
2011/1/5
/
1169
<div> <table style="font-family: monospace" class="vbnet codes"> <tbody> <tr class="li1"> <td style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"> <pre style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"><span style="color: #0000ff">Private</span> <span style="color: #0600ff">Function</span> getCurrentDateAndTime<span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0600ff">Dim</span> strTemp <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #008000">=</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Month</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">"/"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Day</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">"/"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Year</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">" "</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Hour</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">":"</span> <span style="color: #0600ff">If</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span> < <span style="color: #ff0000">10</span> <span style="color: #0000ff">Then</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">"0"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">Else</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0600ff">End</span> <span style="color: #0600ff">If</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">":"</span> <span style="color: #0600ff">If</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span> < <span style="color: #ff0000">10</span> <span style="color: #0000ff">Then</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">"0"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">Else</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0600ff">End</span> <span style="color: #0600ff">If</span> <span style="color: #0000ff">Return</span> strTemp <span style="color: #0600ff">End</span> <span style="color: #0600ff">Function</span></pre> </td> </tr> </tbody> </table> <table style="font-family: monospace" class="vbnet codes"> <tbody> <tr class="li1"> <td style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"> <pre style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"><span style="color: #0000ff">Private</span> <span style="color: #0600ff">Function</span> getCurrentDateAndTime<span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0600ff">Dim</span> strTemp <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #008000">=</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Month</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">"/"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Day</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">"/"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Year</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">" "</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Hour</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">":"</span> <span style="color: #0600ff">If</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span> < <span style="color: #ff0000">10</span> <span style="color: #0000ff">Then</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">"0"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">Else</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0600ff">End</span> <span style="color: #0600ff">If</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">":"</span> <span style="color: #0600ff">If</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span> < <span style="color: #ff0000">10</span> <span style="color: #0000ff">Then</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">"0"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">Else</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0600ff">End</span> <span style="color: #0600ff">If</span> <span style="color: #0000ff">Return</span> strTemp <span style="color: #0600ff">End</span> <span style="color: #0600ff">Function</span></pre> </td> </tr> </tbody> </table> <table style="font-family: monospace" class="vbnet codes"> <tbody> <tr class="li1"> <td style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"> <pre style="line-height: 150%; font-family: Verdana, Monospace; font-size: 12px; font-weight: bold; margin-right: 10px"><span style="color: #0000ff">Private</span> <span style="color: #0600ff">Function</span> getCurrentDateAndTime<span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #0600ff">Dim</span> strTemp <span style="color: #0000ff">As</span> <span style="color: #0000ff">String</span> <span style="color: #008000">=</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Month</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">"/"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Day</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">"/"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Year</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">" "</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Hour</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #008000">&</span> <span style="color: #808080">":"</span> <span style="color: #0600ff">If</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span> < <span style="color: #ff0000">10</span> <span style="color: #0000ff">Then</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">"0"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">Else</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Minute</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0600ff">End</span> <span style="color: #0600ff">If</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">":"</span> <span style="color: #0600ff">If</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span> < <span style="color: #ff0000">10</span> <span style="color: #0000ff">Then</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #808080">"0"</span> <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0000ff">Else</span> strTemp <span style="color: #008000">=</span> strTemp <span style="color: #008000">&</span> <span style="color: #0600ff">Now</span>.<span style="color: #0600ff">Second</span>.<span style="color: #0000ff">ToString</span><span style="color: #000000">(</span><span style="color: #000000">)</span> <span style="color: #0600ff">End</span> <span style="color: #0600ff">If</span> <span style="color: #0000ff">Return</span> strTemp <span style="color: #0600ff">End</span> <span style="color: #0600ff">Function</span></pre> </td> </tr> </tbody> </table> Private Function getCurrentDateAndTime() As String Dim strTemp As String = Now.Month.ToString() & "/" & Now.Day.ToString() & "/" & Now.Year.ToString() strTemp = strTemp & " " & Now.Hour.ToString() & ":" If Now.Minute < 10 Then strTemp = strTemp & "0" & Now.Minute.ToString() Else strTemp = strTemp & Now.Minute.ToString() End If strTemp = strTemp & ":" If Now.Second < 10 Then strTemp = strTemp & "0" & Now.Second.ToString() Else strTemp = strTemp & Now.Second.ToString() End If Return strTemp End Function </div>
试试其它关键字
日期和时间
同语言下
.
根据User Agent来判定操作系统与浏览器类型
.
将PPT内容导出为JPG图片
.
Java屏幕截取
.
发送邮件组件
.
子窗体在父窗体指定的控件中显示
.
取文件的大小
.
从某个目录中筛选文件
.
VB脚本调用exe应用程序并传递参数
.
图像格式转换工具
.
洗牌算法
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
贡献的其它代码
Label
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3