如何用js改写此函数(我对js不熟)(50分)

  • 主题发起人 主题发起人 tokey
  • 开始时间 开始时间
T

tokey

Unregistered / Unconfirmed
GUEST, unregistred user!
function Mysubstr(inputDate:Tdatetime):string;
var
tempstr:string;
begin
datetimetostring(tempstr,'YYYYMMDD',inputDate);
tempstr:=copy(tempstr,1,6);
result:=tempstr;
end;
 
就是要取年月是吧
<script language="javascript">
<!--
var today = new Date();
do
cument.write((today.getYear()) + (today.getMonth() + 1 ));
//--?
</script>
 
好象刚才写错了 [:)]
<script language="javascript">
<!--
var today = new Date();
if(today.getMonth()<9)
do
cument.write((today.getYear()) +'0'+ (today.getMonth() + 1 ))
else
do
cument.write((today.getYear()) +''+ (today.getMonth() + 1 ))
//-->
</script>
 
要传入参数
 
谢谢pihome的帮助,我编的一个,测试是错的,大家看了不要笑我
我以前从来没有接触js,
<script language="javascript">
function Getsubstr(inputdate)
<!--
var sYear;
var SMonth;
var ss;
syear=inputdate.getyear();
Smonth=inputdate.getmonth();
if Smonth<10
ss='0'+str(smonth)
else
ss=str(smonth);
ss=str(syear)+ss;
return ss;
//-->
</script>
 
应该这样写:
<script language="javascript">
<!--
function Mysubstr(inputDate)
{
if(inputDate.getMonth()<9)
{
return (inputDate.getYear()) +"0"+ (inputDate.getMonth() + 1);
}
else
{
reture (inputDate.getYear()) +""+ (inputDate.getMonth() + 1);
}
}

do
cument.write(Mysubstr(new Date()));
//-->
</script>
 
在次感谢pihome的帮助
 
<script language="javascript">
function getYearMonth(myDate){
var curDate=new Date(myDate);
return(curDate.getFullYear()+(curDate.getMonth()<9 ? '0':'')+(curDate.getMonth() + 1));
}
alert(getYearMonth('11/12/2004'));
</script>
 
后退
顶部