格式当前日期和时间 [英] Format current date and time

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

问题描述

我在想,如果有人可以帮助我。

I was wondering if someone could help me.

我很新的ASP我想格式化当前日期和时间如下:

I'm very new at ASP I want to format the current date and time as follows:

yyyy-mm-dd hh:mm:ss

但是,所有我能做的就是以下

But all i can do is the following

Response.Write Date

有人可以帮我请。

Can someone help me out please.

推荐答案

日期格式选项在传统的ASP默认的限制,有一个函数的FormatDateTime()从而可以格式化你的日期是基于服务器的区域设置的各种方法。

Date formatting options are limited in Classic ASP by default, there is a function FormatDateTime() which can format your date is various ways based on the servers regional settings.

在过去的日期格式更多的控制,虽然有建于日期时间函数

For more control over date formatting though there are built in date time functions


  • 年度(日期) - 返回一个整数重新presenting的一年。通过日期()将归还当年。

  • Year(date) - Returns a whole number representing the year. Passing Date() will give back the current year.

月(日期) - 返回1到12之间的整数,包容,再presenting一年的月份。通过日期()将返回当前月份的一年。

Month(date) - Returns a whole number between 1 and 12, inclusive, representing the month of the year. Passing Date() will return the current month of the year.

MONTHNAME(月[,abbv]) - 返回一个字符串,指示指定月份。传递月(DATE())作为本月将归还当月的字符串。 的建议通过 @Martha

MonthName(month[, abbv]) - Returns a string indicating the specified month. Passing in Month(Date()) as the month will give back the current Month string. As suggested by @Martha

日(日) - 返回1到31之间的整数,包容,再presenting月份的一天。通过日期()将返回月的当前日。

Day(date) - Returns a whole number between 1 and 31, inclusive, representing the day of the month. Passing Date() will return the current day of the month.

小时(时间) - 返回0到23之间的整数,包容,再presenting一天的小时。通过时间()将返回当前小时。

Hour(time) - Returns a whole number between 0 and 23, inclusive, representing the hour of the day. Passing Time() will return the current hour.

分钟(时间) - 返回0到59的整数,包容,再presenting小时的分钟。通过时间()将返回当前分钟。

Minute(time) - Returns a whole number between 0 and 59, inclusive, representing the minute of the hour. Passing Time() will return the current minute.

二(时间) - 返回0到59的整数,包容,再presenting分钟的第二个。通过时间()将返回当前第二。

Second(time) - Returns a whole number between 0 and 59, inclusive, representing the second of the minute. Passing Time() will return the current second.

功能月()日()小时()分钟()二()都返回整数。幸运的是,有一个简单的解决方法,可以让你垫这些值迅速右键(00&放大器;值,2)它做什么是追加 00 的值前面,然后从右边取前两个字符。这将确保所有单位数的值返回与pfixed $ P $一个 0

The functions Month(), Day(), Hour(), Minute() and Second() all return whole numbers. Luckily there is an easy workaround that lets you pad these values quickly Right("00" & value, 2) what it does is append 00 to the front of the value then from the right take the first two characters. This ensures that all single digit values return prefixed with a 0.

Dim dd, mm, yy, hh, nn, ss
Dim datevalue, timevalue, dtsnow, dtsvalue

'Store DateTimeStamp once.
dtsnow = Now()

'Individual date components
dd = Right("00" & Day(dtsnow), 2)
mm = Right("00" & Month(dtsnow), 2)
yy = Year(dtsnow)
hh = Right("00" & Hour(dtsnow), 2)
nn = Right("00" & Minute(dtsnow), 2)
ss = Right("00" & Second(dtsnow), 2)

'Build the date string in the format yyyy-mm-dd
datevalue = yy & "-" & mm & "-" & dd
'Build the time string in the format hh:mm:ss
timevalue = hh & ":" & nn & ":" & ss
'Concatenate both together to build the timestamp yyyy-mm-dd hh:mm:ss
dtsvalue = datevalue & " " & timevalue

Call Response.Write(dtsvalue)

注意: 您可以建立一个呼叫日期字符串,但决定把它分成三个变量,使其更容易阅读

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

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