日期格式检测脚本

< script language = " javascript " >
// 函数名:chkdate
//
功能介绍:检查是否为日期
//
参数说明:要检查的字符串
//
返回值:0:不是日期  1:是日期

function  chkdate(datestr)
{
 
var lthdatestr
 
if (datestr != "")
  lthdatestr
= datestr.length ;
 
else
  lthdatestr
=0;
  
 
var tmpy="";
 
var tmpm="";
 
var tmpd="";
 
//var datestr;
 var status;
 status
=0;
 
if ( lthdatestr== 0)
  
return 0

 
for (i=0;i<lthdatestr;i++)
 
if (datestr.charAt(i)== '-')
  
{
   status
++;
  }

  
if (status>2)
  
{
   
//alert("Invalid format of date!");
   return 0;
  }

  
if ((status==0&& (datestr.charAt(i)!='-'))
  
{
   tmpy
=tmpy+datestr.charAt(i)
  }

  
if ((status==1&& (datestr.charAt(i)!='-'))
  
{
   tmpm
=tmpm+datestr.charAt(i)
  }

  
if ((status==2&& (datestr.charAt(i)!='-'))
  
{
   tmpd
=tmpd+datestr.charAt(i)
  }

 }

 year
=new String (tmpy);
 month
=new String (tmpm);
 day
=new String (tmpd)
 
//tempdate= new String (year+month+day);
 //alert(tempdate);
 if ((tmpy.length!=4|| (tmpm.length>2|| (tmpd.length>2))
 
{
  
//alert("Invalid format of date!");
  return 0;
 }

 
if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
 
{
  
//alert ("Invalid month or day!");
  return 0;
 }

 
if (!((year % 4)==0&& (month==2&& (day==29))
 
{
  
//alert ("This is not a leap year!");
  return 0;
 }

 
if ((month<=7&& ((month % 2)==0&& (day>=31))
 
{
  
//alert ("This month is a small month!");
  return 0;
 
 }

 
if ((month>=8&& ((month % 2)==1&& (day>=31))
 
{
  
//alert ("This month is a small month!");
  return 0;
 }

 
if ((month==2&& (day==30))
 
{
  
//alert("The Febryary never has this day!");
  return 0;
 }

 
 
return 1;
}

</ script >
 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
时差检测脚本(shell script)是一种用于检测多个计算机之间时差的脚本程序。在计算机网络环境中,由于各个计算机的时钟存在微小的差异,导致在进行时间同步等操作时可能出现问题。因此,通过编写一个时差检测脚本可以方便地检测和计算各个计算机之间的时差,以保证时间同步的准确性和可靠性。 时差检测脚本的原理是通过向多个计算机发送时间同步请求,并获取各个计算机的系统时间。然后,通过对比各个计算机的系统时间,计算并比较它们之间的时差。通常,可以使用计算机内置的命令如date获取系统时间,并进行时间计算和比较。在脚本中,可以使用循环结构和条件判断等控制流语句来实现对多个计算机的遍历和计算。 时差检测脚本的编写需要考虑以下几个要点:首先,需要定义要检测的计算机列表,包括它们的IP地址或主机名;其次,需要建立与每个计算机的网络连接,并发送时间同步请求;然后,获取各个计算机的系统时间,并进行时差的计算;最后,输出时差结果,并根据需要采取措施进行时间调整或同步。 时差检测脚本的应用场景广泛,比如在分布式系统中,通过定期执行该脚本可以检测和修正各个计算机之间的时差,避免因时差导致的数据不一致等问题。此外,在日志分析、系统监控等场景中,时差检测脚本也可以用来判断计算机是否处于正确的时间状态,以便进行相应的处理和分析。 总之,时差检测脚本是一种非常实用的工具,可以帮助我们准确地检测和计算多个计算机之间的时差,保证时间同步的精确性和可靠性。同时,通过对时差的检测和调整,还可以提高分布式系统和网络环境下各种应用的性能和效率。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值