国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

javascript asp教程 日期相關(guān)

2024-05-04 10:58:18
字體:
供稿:網(wǎng)友

JavaScript is loosely typed. Database files are not. If you put text into a Boolean database column or a Boolean value into a date/time column, then you will get an error.

For the most part this is not a problem, except for date/time. It does not correspond to the JavaScript Date Object. So, we have to tear Date apart and rebuild it from scratch. If we don't, then we get a type mismatch error.

Take a look at the snippet below. (It's not part of our lesson, but I want you to look at it anyway.) Please notice DateTime.

objConn.Open(strConnect)sql = "INSERT INTO FoloVisit (SessionID,VisitTime) "sql+= "Values ('" + Session.SessionID + "',#" + DateTime + "#);"objConn.Execute(sql)

DateTime has to be in a very particular format: #mm/dd/yyyy hh:mm:ss [a|p]m# As you well know new Date() doesn't even come close to this format. We will fix that in the script below.

Get Started:

Below is the script for Lesson 20.

<%@LANGUAGE="JavaScript"%><SCRIPT LANGUAGE="VBScript" RUNAT="Server">Dim VBTime,VBDate,VBDateTimeVBTime = Time & " "VBDate = Date & " "VBDateTime = Date & " " & Time</SCRIPT><%function whatTimeIsIt()	{	var m=new Date()	var minute=m.getMinutes()	var second=m.getSeconds()	var ampm=false	if (minute >=0 && minute < 10)		{ minute=("0" + minute)	}	if (second >= 0 && second < 10 )		{ second=("0" + second) }	var hours=m.getHours()	if (hours > 12)		{ ampm=true		hours=hours-12 }	if (hours==12)		{ ampm=true }	if (hours == 0)		{ hours=hours+12		ampm=false }	if (ampm)		{ ampm=" PM" }	else		{ ampm=" AM" }	var myTime=hours + ":" + minute + ":" + second + ampm	return myTime;	}var DateTime = new Date();var Month = (DateTime.getMonth() + 1) + "/";var Day = DateTime.getDate() + "/";var Year = DateTime.getFullYear();var JustTheDate = Month + Day + Year;var JustTheTime = whatTimeIsIt();var DateTime = Month + Day + Year + " " + whatTimeIsIt();Response.Write("<HTML>/r")Response.Write("<STRONG>JavaScript Time</STRONG><BR>/r")Response.Write("The date in proper database format is: " + JustTheDate + "<BR>/r")Response.Write("The time in proper database format is: " + JustTheTime + "<BR>/r")Response.Write("The date & time together are: " + DateTime + "<BR>/r")Response.Write("<HR>/r")Response.Write("<STRONG>VBScript Time</STRONG><BR>/r")Response.Write("The date in proper database format is: " + VBDate + "<BR>/r")Response.Write("The time in proper database format is: " + VBTime + "<BR>/r")Response.Write("The date & time together are: " + VBDateTime + "<BR>/r")Response.Write("</HTML>")%>

Click Here to run the script in a new window.

Living on VBScript Time:

The other way to solve the problem is to use the VBScript date and time Objects. What can I say? If you can't beat 'em, steal from 'em!

Time For a Tangent:

If all you want to do is store

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 四会市| 尚义县| 遂平县| 金湖县| 呼图壁县| 阿图什市| 洞口县| 丹阳市| 五家渠市| 双城市| 叶城县| 禄丰县| 富锦市| 桦南县| 琼中| 商洛市| 徐闻县| 瓦房店市| 揭东县| 济宁市| 华池县| 内乡县| 安西县| 虹口区| 澄城县| 竹山县| 铅山县| 新郑市| 姚安县| 汕头市| 商丘市| 旅游| 高雄县| 桃源县| 萝北县| 西青区| 驻马店市| 新野县| 禹州市| 淮阳县| 驻马店市|