• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP > javascript asp教程 日期相关

javascript asp教程 日期相关

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了javascript asp.net,asp javascript,javascript日期函数,javascript 日期,javascript日期加减等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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,VBDateTime
VBTime = 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 new Date() exactly as-is in your database then do so in a text or memo column. The disadvantage of using this tactic is that SQL cannot sort items correctly by date and time. Instead, they'll be sorted by alphabetical order.

Final Thoughts:

That's the end of the lesson plan. I have received messages from all over the world. Thank you for your kind words. If you have questions or comments you can click onto the link for the home page and then there's a link to contact me.

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • asp cookie中文Javascript取得中文cookie
  • JavaScript在ASP页面中实现掩码文本框效果代码
  • asp中去除html中style,javascript,css代码
  • asp(JavaScript)自动判断网页编码并转换的代码
  • asp javascript值的互相传递方法
  • asp+javascript实现404页的处理转换
  • ASP之处理用Javascript动态添加的表单元素数据的代码
  • asp编程中常用的javascript辅助代码第1/2页
  • ASP中JavaScript处理复杂表单的生成与验证第1/3页
  • javascript asp教程 日期相关

相关文章

  • 2017-05-11隐藏ASP木马后门的两种方法
  • 2017-05-11asp中利用CSW中文分词组件来实现自己网站的内容关键词自动提取
  • 2017-05-11用asp实现网页调用doc附Response.ContentType 详细列表
  • 2017-05-11asp知识整理笔记1(问答模式)
  • 2017-05-11ASP 中 DateDiff 函数详解 主要实现两日期加减操作
  • 2017-05-11ASP页面静态化批量生成代码分享(多种方法)
  • 2017-05-11PostHttpPage用asp是实现模拟登录效果的代码
  • 2017-05-11XMLHTTP利用POST发送表单时提交中文的问题
  • 2017-05-11可以查询百度排名的asp源码放送了
  • 2017-05-11asp OpenTextFile文本读取与写入实例代码

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • ASP实现强制图片下载函数
    • 利用FSO取得BMP,JPG,PNG,GIF文件信息
    • asp之基于adodb.stream的文件操作类
    • SQL查询语句通配符与ACCESS模糊查询like的解决方法
    • asp 横排显示数据
    • ASP中实现定时发送邮件的代码分享
    • CHR(10)表示换行,CHR(13)表示回车,CHR(32)表示空格
    • 数据库记录的删除,delete好还是update好?
    • 好久没发布新玩意,完成了tsys的少年不在版
    • 解决ASP(图像)上传漏洞的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有