javascript相当于vbscript Date() - 1 [英] javascript equivalent for vbscript Date()-1
问题描述
我希望仅在昨天的日期返回日期。没有秒,
毫秒。格式化为yyyy / mm / dd或mm / dd / yyyy。 VB这样做很容易
日期() - 1如果今天是03/28/2007将返回03/27/2007。为什么如此
javascript的许多箍?有什么想法吗?
I''m looking to return DATE ONLY for yesterday''s date. No seconds,
milliseconds. Formatted either yyyy/mm/dd or mm/dd/yyyy. VB does it so
easily Date()-1 will return 03/27/2007 if today is 03/28/2007. Why so
many hoops for javascript? Any ideas?
推荐答案
" shelleybobelly" < sh ************ @ yahoo.comschreef在bericht
新闻:11 ****************** ****@e65g2000hsc.googlegr oups.com ...
"shelleybobelly" <sh************@yahoo.comschreef in bericht
news:11**********************@e65g2000hsc.googlegr oups.com...
我希望仅在昨天的日期返回日期。没有秒,
毫秒。格式化为yyyy / mm / dd或mm / dd / yyyy。
I''m looking to return DATE ONLY for yesterday''s date. No seconds,
milliseconds. Formatted either yyyy/mm/dd or mm/dd/yyyy.
切勿使用后一种格式。这对全世界的观众来说非常困惑。
var x = new Date();
var s = x.getFullYear()+'' /''+ x.getMonth()+''/''+ x.getDate();
alert(s);
Never use the latter format. It ''s highly confusing to a worldwide audience.
var x = new Date();
var s = x.getFullYear() + ''/'' + x.getMonth() + ''/'' + x.getDate();
alert( s );
VB这样做很容易
日期() - 1如果今天是03/28/2007将返回2007年3月27日。为什么
这么多javascript的箍?有任何想法吗?
VB does it so
easily Date()-1 will return 03/27/2007 if today is 03/28/2007. Why
so many hoops for javascript? Any ideas?
这是一个非常好的问题。我想答案包括Javascript通过将所有格式保留给我们来提供的灵活性。
hth
ivo
http://4umi.com/web/javascript/ref.htm#date
" Ivo" < no@thank.youschreef
"Ivo" <no@thank.youschreef
" shelleybobelly" < sh ************ @ yahoo.comschreef
"shelleybobelly" <sh************@yahoo.comschreef
>我希望仅在昨天返回日期''约会。
>I''m looking to return DATE ONLY for yesterday''s date.
我忘了减去一天,还有一行代码:
var x = new Date ();
x.setDate(x.getDate() - 1);
var s = x.getFullYear()+''/''+ x.getMonth ()+''/''+ x.getDate();
alert(s);
hth
ivo
http://4umi.com/web/javascript/ ref.htm #date
3月28日上午11:19,Ivo < n ... @ thank.youwrote:
On Mar 28, 11:19 am, "Ivo" <n...@thank.youwrote:
我忘了减去一天,再增加一行代码:
var x = new Date();
x.setDate(x.getDate() - 1);
var s = x.getFullYear()+'' /''+ x.getMonth()+''/''+ x.getDate();
alert(s);
I forgot to substract a day, one more line of code:
var x = new Date();
x.setDate( x.getDate() - 1 );
var s = x.getFullYear() + ''/'' + x.getMonth() + ''/'' + x.getDate();
alert( s );
或
var x = new Date();
var s = x.getFullYear()+''/''+ x.getMonth()+''/ ''+(x.getDate() - 1);
alert(s);
or
var x = new Date();
var s = x.getFullYear() + ''/'' + x.getMonth() + ''/'' + (x.getDate()-1);
alert( s );
这篇关于javascript相当于vbscript Date() - 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!