易截截图软件、单文件、免安装、纯绿色、仅160KB

java获取当前日期的前一天日期与字符串日期之间的转换

         这几天一直在处理Java的日期问题,通常需要按要求生成日期的话,通常会用到util包中的Calendar类,再用Calendar的getTime()方法生成对应的Date,最后用SimpleDateFormat输出。
 
1. 获取当期日期、年份、月份
import java.util.Calendar;
public class Main {
  public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current Year is : " + now.get(Calendar.YEAR));
    // month start from 0 to 11
    System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1));
    System.out.println("Current Date is : " + now.get(Calendar.DATE));
  }
}
 
2. 获取前一天、前一个月的日期
Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
        calendar.add(Calendar.DATE, -1);    //得到前一天
String  yestedayDate
= new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        calendar.add(Calendar.MONTH, -1);    //得到前一个月
        int year = calendar.get(Calendar.YEAR);
       int month = calendar.get(Calendar.MONTH)+1; //输出前一月的时候要记得加1
 
3. 字符串转为日期格式
String date = "2010-02-01 23:59:59";
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date d = sf.parse(date);
System.out.println(sf.format(d));
} catch (ParseException e) {
e.printStackTrace();
}


相关文档:

java多叉树遍历

而且java提供的容器类很方便,手工构造了一颗多叉树。然后再递归遍历。类似于中序遍历吧。
树的节点类:
Java代码
package TestTwo;   
  
import java.util.ArrayList;   
import java.util.List;   
  
//多叉树的节点  &nbs ......

java常用设计模式


单例模式.
简而言之,就是一个类只有一个实例。
Singleton.java:
package com.xfimti.sigleton;
public class Singleton
{
 /*第一种方式。*/
 private static Singleton singleton = new Singleton();
 /*第二种方式。*/
 private static Singleton mySingleton = null;
 
 p ......

Java中serialVersionUID的解释


<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......

Java输入数据流详解


<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号