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" ); ==!
(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" ); ==!
相关文章推荐
- 对比JAVA学习PHP系列:应用:php的日期和时间
- java获取时间戳的方法对比
- 计算日期时间 自动加1天 PHP计算闰年 java与PHP时间戳对比区别
- 简洁版:java获取时间之后,对比开始时间和结束时间,对比活动状态
- PHP与Java对比学习日期时间函数
- JAVA获取各种各样的时间、时间对比 方法汇总
- java获取时间戳的方式 和几种方式速度对比
- 对比一下PHP和JAVA开发网站的优劣
- PHP与Java对比学习日期时间函数
- java获取当天,前天,明天,本周,本月,本年的开始日期时间和结束日期时间(总结一下,以后直接拿来用)
- 对比一下PHP和JAVA开发网站的优劣
- 对比一下PHP和JAVA开发网站的优劣
- 【Java】从网络获取北京时间
- JAVA中获取当前系统时间和String转换
- Java获取当前时间
- JAVA中获取当前系统时间
- Java获取当前时间
- java 获取当前系统时间 时间比较
- PHP 获取北京时间
- php获取未来一周的每天时间