您的位置:首页 > 编程语言 > PHP开发

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

2007-08-14 11:34 585 查看
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" ); ==!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: