Add or substract minutes to current time using Java Calendar
/*
Add or substract minutes to current time using Java Calendar
This example shows how to add or substract minutes in current time
using Java Calendar class.
*/
import java.util.Calendar;
public class AddMinutesToCurrentDate {
public static void main(String[] args) {
//create Calendar instance
Calendar now = Calendar.getInstance();
System.out.println("Current time : " + now.get(Calendar.HOUR_OF_DAY)
+ ":"
+ now.get(Calendar.MINUTE)
+ ":"
+ now.get(Calendar.SECOND));
//add minutes to current date using Calendar.add method
now.add(Calendar.MINUTE,20);
System.out.println("New time after adding 20 minutes : "
+ now.get(Calendar.HOUR_OF_DAY)
+ ":"
+ now.get(Calendar.MINUTE)
+ ":"
+ now.get(Calendar.SECOND));
/*
* Java Calendar class automatically adjust the date or hour accordingly
if adding minutes to the current time causes current hour or date to be changed.
*/
//substract minutes from current date using Calendar.add method
now = Calendar.getInstance();
now.add(Calendar.MINUTE, -50);
System.out.println("Time before 50 minutes : " + now.get(Calendar.HOUR_OF_DAY)
+ ":"
+ now.get(Calendar.MINUTE)
+ ":"
+ now.get(Calendar.SECOND));
}
}
/*
Typical output would be
Current time : 16:34:11
New time after adding 20 minutes : 16:54:11
Time before 25 minutes : 15:44:11
*/
2011年7月11日 星期一
2011年2月18日 星期五
2010年12月15日 星期三
Java Date function
Java Date function的使用
Java SimpleDateFormat Class Example
台灣限定:
DateFormat formatter = new SimpleDateFormat("MMM",Locale.US);
卡一個台灣限定,害我以為我的java有問題,搞了一個上午...
感謝蕭惠芳大大,幫忙解決難題。
Java SimpleDateFormat Class Example
台灣限定:
DateFormat formatter = new SimpleDateFormat("MMM",Locale.US);
卡一個台灣限定,害我以為我的java有問題,搞了一個上午...
感謝蕭惠芳大大,幫忙解決難題。
2010年12月13日 星期一
2010年11月10日 星期三
2009年8月7日 星期五
JPanel background
The easiest way to do this is to extend JPanel and override the paintComponent method.
public void paintComponent( Graphics g )
{
super.paintComponent( g );
Graphics2D g2d = (Graphics2D) g;
}
cf
public void paintComponent( Graphics g )
{
super.paintComponent( g );
Graphics2D g2d = (Graphics2D) g;
}
cf
2008年10月30日 星期四
2008年8月29日 星期五
2008年8月20日 星期三
2007年12月3日 星期一
訂閱:
文章 (Atom)