【问题标题】:Calculating Date in Java用Java计算日期
【发布时间】:2013-04-01 10:03:39
【问题描述】:

好的,我正在尝试以这种格式创建日期:

SimpleDateFormat dateformat = new SimpleDateFormat("dd-MM-yy");

我无法计算那个日期,所以它给了我 2013 年 1 月 1 日。

Date newdate = new Date (136199001);
String date = dateformat.format(newdate);

但是我不知道如何才能到达我想要的日期。我知道我应该从 70 年 1 月 1 日开始解决,但我遇到了麻烦。问题:计算日期的公式是什么?

【问题讨论】:

  • 你的问题是什么?
  • Date newdate = dateformat.parse("01-01-13"); ?
  • for 1/1/13 ,1356978600000 应该输入检查其他方式... .新日期.getTime();对于 01-01-13 的新日期

标签: java string date math format


【解决方案1】:

我会说你正在寻找的是这个:

new SimpleDateFormat("dd/MM/yy").parse("1/1/13");

【讨论】:

    【解决方案2】:

    您可以将日历对象用于特定日期。这要容易得多。

    Calendar cal = Calendar.getInstance();
    cal.set(2013, 0, 1); //1st january 2013
    Date date = cal.getTime();
    SimpleDateFormat dateformat = new SimpleDateFormat("dd-MM-yy");
    String dateStr = dateformat.format(date);
    

    【讨论】:

      猜你喜欢
      • 2014-06-17
      • 2016-12-08
      • 2010-10-13
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多