ASP Format Date and Time Script

ASP has a very handy inbuild function called FormatDateTime().

Let's start with the now() function to get the current date and time into a variable


<% 
dim todaysDate
 todaysDate=now() 
%>


Now we can use the FormatDateTime function to format our date variable in a variety of ways.

First let's see how todaysDate appears :

<% 
Response.write todaysDate 
%>

RESULT: 2/14/2005 12:34:41 PM

Using 0 - the vbGeneralDate format creates a date as short date (if included), and time as long time.


<% 
Response.write FormatDateTime(todaysDate,0) %>

RESULT:
2/14/2005 12:34:41 PM

Using 1 - the vbLongDate shows the date as long date


<% 
Response.write FormatDateTime(todaysDate,1)
%>


RESULT: Monday, February 14, 2005

Using 2 - the vbShortDate shows the date as short date

<% 
Response.write FormatDateTime(todaysDate,2) 
%>


RESULT: 2/14/2005


Using 3 - the vbLongTime format shows the time as long time .


<% 
Response.write FormatDateTime(todaysDate,3)
%>


RESULT: 12:34:41 PM


Using 4 - the vbShortTime format creates the current time in 24 format (hh:mm)




<%
Response.write FormatDateTime(todaysDate,4) 
%>


RESULT: 12:34



International Date and Time

You can use the session.lcid property to change the formatting of the date and time.

For example
<%session.lcid=2057%>
will set the date and time to UK format (DD/MM/YYYY instead of MM/DD/YYYY ) Here's a list of international locales. Bear in mind that setting these will also change currency formatting.

Locale ID (LCID)Description
1033General Unicode
33280Binary Order
1027Catalan
197636Chinese Bopomofo (Taiwan)
2052Chinese Punctuation
133124Chinese Stroke Count
1028Chinese Stroke Count (Taiwan)
1050Croatian
1029Czech
1043Dutch
1061 Estonian
1036French
66615Georgian Modern
1031German
66567German Phone Book
1038Hungarian
66574Hungarian Technical
1039Icelandic
1040Italian
1041Japanese
66577Japanese Unicode
1042Korean
66578Korean Unicode
1062Latvian
1063Lithuanian
1071 FYRO Macedonian
1044Norwegian/Danish
1045Polish
1046Portuguese
1048Romanian
1051Slovak
1060Slovenian
1034Spanish (Traditional)
3082Spanish (Spain)
1053Swedish/Finnish
1054Thai
2057UK English
1058 Ukrainian
1066Vietnamese



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值