Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Example Java Util CurrentTime

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

5 comments so far (post your own) View All Comments Latest 10 Comments:

My system timezone is +3:30
But I add to my time +1 hour.(+4:30)

I tested this code (int hour = calendar.get(Calendar.HOUR);) but this code return what is matched by +3:30.

Posted by Mojtaba on Friday, 06.18.10 @ 00:04am | #97649

thanks i was trying to find out how to do this and not just print out the simple format like other sites give.

Posted by Luke on Friday, 09.11.09 @ 03:24am | #90799

I want to start an activity with am of another after the end of the execution time of the first one. can you help me please

Posted by foufou on Sunday, 03.29.09 @ 22:01pm | #86322

import java.util.*;
import java.lang.String.*;
import java.util.Date.*;

class DateTimeThread extends Thread{

/*public void start()
{
System.out.println("\nIN RUN");
datetimeThread = new Thread(this);
datetimeThread.start();
}*/

void datetimeThread()
{
}

public void run()
{
System.out.println("\nIN RUN");
Thread datetimeThread1 = Thread.currentThread();
while(datetimeThread1 != null)
{
System.out.println("\nIN while");
display();
try
{
datetimeThread1.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("Thread interrupted");
}
}
}

public void display()
{
System.out.println("\nIN DISPLAY");
Date date = new Date();
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
if (calendar.get(Calendar.AM_PM) == 0)
{
am_pm = "AM";
}
else
{
am_pm = "PM";
}
String strTime = ("Current Time : " + hour + ":" + minute + ":" + second + " " + am_pm);
String strDate = (calendar.get(Calendar.MONTH))+"/"+calendar.get(Calendar.DATE)+"/"+calendar.get(Calendar.YEAR);
String strStatus=(strTime+" "+"Current Date " + strDate);
System.out.println(strStatus);
}

public static void main(String args[])
{
Thread datetimeThread=new DateTimeThread();
datetimeThread.start();
}
}

Posted by Sandesh and Ajit on Saturday, 03.21.09 @ 01:55am | #86074

This code i have learnt and applied in my project but its nt getting the system time. When i run it ordinary it got the sys time but when i applied it on a gui it didnt work.
This is a thread.

public void dateTime()
{
datetimeThread = new Thread(this);

datetimeThread.start();
}

public void run()
{
while(datetimeThread != null)
{
display();
try
{
datetimeThread.sleep(1000);
}
catch(InterruptedException e)
{
showStatus("Thread interrupted");
}
}
}

public void display()
{
date = new Date();
calendar = new GregorianCalendar();
calendar.setTime(date);
String am_pm;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
if (calendar.get(Calendar.AM_PM) == 0)
{
am_pm = "AM";
}
else
{
am_pm = "PM";
}
strTime = ("Current Time : " + hour + ":" + minute + ":" + second + " " + am_pm);
strDate = (calendar.get(Calendar.MONTH)+1)+"/"+calendar.get(Calendar.DATE)+"/"+calendar.get(Calendar.YEAR);
strStatus=strTime+" "+"Current Date " + strDate;
showStatus(strStatus);
}

Posted by Emeka Nwankwo on Sunday, 11.30.08 @ 02:34am | #82191

Ask programming questions?

 

 

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.