RSS
热门关键字:  java  Ajax  JSP  JSF  Struts
当前位置 : 首页>Spring>列表

java中获取时间(顺面对比一下php获取时间)

来源: 作者: 时间:2007-08-14 点击:
 Java中获取时间:
(1) 使用SimpleDateFormat类
import java.text.SimpleDateFormat;
public class GetCurrentDate {

    /**
     * @param args
     */
    public static void main(String[] args) {
        SimpleDateFormat tempDate = new SimpleDateFormat( "yyyy-MM-dd" + " " + "hh:mm:ss" );
        String datetime = tempDate.format( new java.util.Date() );
        System.out.println( datetime );
    }

}
    (2)使用Calendar
import java.util.Calendar;


public class GetCurrentDate {

    private static final Calendar Calendar = null;

    /**
     * @param args
     */
    public static void main(String[] args) {      
       
        Calendar now = Calendar.getInstance();
        String time = now.get( Calendar.YEAR )+"-"+( now.get( Calendar.MONTH ) + 1 ) + "-" + now.get( Calendar.DAY_OF_MONTH ) + " "
        + now.get( Calendar.HOUR_OF_DAY ) + ":" + now.get( Calendar.MINUTE ) + ":" + now.get( Calendar.SECOND );
       
        System.out.println( time );
    }

}

php中获取时间:
date( "Y-m-d H:i:s" ); ==!

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
Google Adsense
相关文章