/**
* 获得当前日期的前一天
*/
function getYestoday(date){
  var yesterday_milliseconds=date.getTime()-1000*60*60*24;//转换成毫秒后减去一天的毫秒数
// var yesterday = new Date();
// yesterday.setTime(yesterday_milliseconds);
//
// var strYear = yesterday.getFullYear();
// var strDay = yesterday.getDate();
// var strMonth = yesterday.getMonth()+1;
// if(strMonth<10)
// {
//   strMonth="0"+strMonth;
// }
//datastr = strYear+"-"+strMonth+"-"+strDay;
return new Date(yesterday_milliseconds);
18 }

大家可根据上面方法扩展获得前一个月的日期、前一年的日期,被注释掉的部分可以转换成你想要的日期格式。

js日期的构造函数:

 new Date()
new Date(milliseconds)
new Date(datestring)
new Date(year, month)
new Date(year, month, day)
new Date(year, month, day, hours)
new Date(year, month, day, hours, minutes)
new Date(year, month, day, hours, minutes, seconds)
new Date(year, month, day, hours, minutes, seconds, microseconds)

具体方法可在这里http://blog.sina.com.cn/s/blog_6a0cd5e501011so7.html浏览

javascript获得给定日期的前一天的日期的更多相关文章

  1. Extjs4 获取到前一天的日期

    Extjs4 获取到前一天的日期 Extjs官方示例 Ext.Date add( date, interval, value ) : Date Provides a convenient method ...

  2. DateTime.IsLeapYear 方法判断是否是闰年,DaysInMonth判断一个月有几天,Addday取得前一天的日期GetYesterDay

    一:DateTime.IsLeapYear 方法判断是否是闰年 二:代码 using System; using System.Collections.Generic; using System.Co ...

  3. javascript两行代码按指定格式输出日期时间

    javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...

  4. java获得指定日期的前一天,后一天的代码

    /** * 获得指定日期的前一天 * @param specifiedDay * @return * @throws Exception */ public static String getSpec ...

  5. JavaScript的内置对象(Date日期+string字符串)基础语法总结

    1.Date日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 1)定义一个时间对象 : var Udate=new Date(); //注意:使用关键字new,Date()的首 ...

  6. java 根据系统日期获取前一天、后一天时间(根据初始日期推算出期望(向前/向后)日期)

      1.情景展示  java 根据系统当前日期获取前一天日期.后一天日期,或者根据初始日期推算出期望(向前/向后)日期. 2.解决方案 导包 import java.text.ParseExcepti ...

  7. php获取指定日期的前一天,前一月,前一年日期

    ## php获取指定日期的前一天,前一月,前一年日期   前一天的日期为: date("Y-m-d",strtotime("-1 days",strtotime ...

  8. java日期获取前一天和后一天

    import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Calendar;import j ...

  9. javascript日期验证:填写的日期大于等于当前日期

    <script> $(function () { var d = new Date(); var strDate = getDateStr(d); $("#beginTime&q ...

随机推荐

  1. 数学 ZJOI 2012 数列

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; ; st ...

  2. form.Show()和form.ShowDialog()的区别、新建一个form和MessageBox.Show()的常见用法

    一:form.Show()和form.ShowDialog()的区别 a. 任何窗体(派生于基类Form的类),都可以以两种方式进行显示. //非模式窗体From qform=new Form();q ...

  3. bzoj 1560 [JSOI2009]火星藏宝图(DP)

    1560: [JSOI2009]火星藏宝图 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 647  Solved: 309[Submit][Status ...

  4. Safecracker(搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1015 / 题意; 从所给的一串字符串中选出5个字母假如是(A B C D E)使得A-B^2+C^3-D^4+E ...

  5. [Locked] Factor combinations

    Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...

  6. windows server作为文件服务器如何精细控制权限

    最近使用windows server 2003搭建了文件服务器,对于其中关于共享文件权限的精细控制有了较深的体会. 当前实现基本的共享文件目录结构是(上传图片真心费劲,大家将就一下吧): |--部门1 ...

  7. hive 模块

  8. js提交前弹出提示框

    <form target="_blank" name="f1" method="post" action="sub2.php ...

  9. 3D游戏引擎一 win32编程

    Windows程序一般都等待用户进行一些操作,然后响应并採取行动. 一般来说.对win32的程序的操作都会转换为系统事件队列中的消息,如按键消息WM_KEYDOWN,WM_MOUSECLICK等传递键 ...

  10. PreTranslateMessage作用和用法

    PreTranslateMessage作用和用法  PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗体的消息都要通过这里,比較经常使用, ...