首页 > 语言 > JavaScript > 正文

获取客户端电脑日期时间js代码(jquery)

2024-05-06 14:21:16
字体:
来源:转载
供稿:网友
原生态javascript获取日期
代码如下:
<SCRIPT LANGUAGE="JavaScript">
var myDate = new Date();
    myDate.getYear();       //获取当前年份(2位)
    myDate.getFullYear();   //获取完整的年份(4位,1970-????)
    myDate.getMonth();      //获取当前月份(0-11,0代表1月)
    myDate.getDate();       //获取当前日(1-31)
    myDate.getDay();        //获取当前星期X(0-6,0代表星期天)
    myDate.getTime();       //获取当前时间(从1970.1.1开始的毫秒数)
    myDate.getHours();      //获取当前小时数(0-23)
    myDate.getMinutes();    //获取当前分钟数(0-59)
    myDate.getSeconds();    //获取当前秒数(0-59)
    myDate.getMilliseconds();   //获取当前毫秒数(0-999)
    myDate.toLocaleDateString();    //获取当前日期
    var mytime=myDate.toLocaleTimeString();    //获取当前时间
    myDate.toLocaleString( );       //获取日期与时间
if (mytime<"23:30:00")
{
alert(mytime);
}
</SCRIPT>

基于jquery获取日期
代码如下:
<!DOCTYPE html>
<html class="no-js">
<head>
    <meta charset="UTF-8">
    <title>当期时间</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
    <style type="text/css">
        .date{height:100px;line-height:100px;margin:0 auto;font-family:Arial, Helvetica, sans-serif;font-size:40px;
        border:solid 1px #ccc;box-shadow:0 0 3px rgba(0,0,0,0.3) inset;border-radius:5px;text-shadow:1px 1px 2px rgba(0,0,0,0.3);}
        .date strong{padding:0 10px;display:inline-block;height:100px;border-right:solid 1px #ccc;}
    </style>
</head>
<body>
    <h1>js简单的获取当前日期和时间</h1>
    <p class="date">
        <strong id="Y"></strong>
        <strong id="MH"></strong>
        <strong id="TD"></strong>
        <strong id="D"></strong>
        <strong id="H"></strong>
        <strong id="M"></strong>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选