Wed Sep 07, 2011 3:12 pm
Thu Sep 08, 2011 10:05 pm
package TextAreaExample;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class ExampleClass {
public static void main(String[] args) {
// Create a calendar instance with system current time.
Calendar calendar = Calendar.getInstance();
// Formating the time .
SimpleDateFormat dateFormat = new SimpleDateFormat("H:mm:ss:SSS");
System.out.println("Current Time(H:mm:ss:SSS) :" + dateFormat.format(calendar.getTime()));
// Another Format
dateFormat = new SimpleDateFormat("yyyyMMdd");
System.out.println("Current Time(yyyyMMdd):" + dateFormat.format(calendar.getTime()));
// Custom Formating.
int currentHour = calendar.get(Calendar.HOUR);
int currentMinute = calendar.get(Calendar.MINUTE);
int currentSeconds = calendar.get(Calendar.SECOND);
String amOrpm="";
if(calendar.get(Calendar.AM)==1){
amOrpm="PM";
}else
{
amOrpm="AM";
}
System.out.println("H:"+currentHour+",m:"+currentMinute+",s:"+currentSeconds+":"+amOrpm);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.