Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to get the time of my machine

  Asked By: Jamil    Date: Jan 12    Category: Java    Views: 974
  

i want ur help
how can i get the time of my pc , i mean what is the java code :)

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Kiet Jainukul     Answered On: Jan 12

java.util.Date date = new java.util.Date()

 
Answer #2    Answered By: Mae Roberts     Answered On: Jan 12


or you take the simple way:

public static String getRightNow() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
return formatter.format(date);
}

but the code  below looks really cool

 
Answer #3    Answered By: Freda Lane     Answered On: Jan 12

some parts of this may be useful......

db

private static String getTimeAsAString()
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(today);
StringBuffer buf = new StringBuffer(16);

buf.append(calendar.get(Calendar.DAY_OF_MONTH));
buf.append('/');
buf.append(calendar.get(Calendar.MONTH)+1);
buf.append('/');
buf.append(calendar.get(Calendar.YEAR));
buf.append(' ');
buf.append(calendar.get(Calendar.HOUR_OF_DAY));
buf.append(':');
if(calendar.get(Calendar.MINUTE)<10)
buf.append('0');
buf.append(calendar.get(Calendar.MINUTE));
/*
buf.append(':');
if(calendar.get(Calendar.SECOND)<10)
buf.append('0');
buf.append(calendar.get(Calendar.SECOND));
buf.append(':');
if(calendar.get(Calendar.MILLISECOND)<10)
buf.append('0');
buf.append(calendar.get(Calendar.MILLISECOND));
*/
return buf.toString();
}

 
Didn't find what you were looking for? Find more on how to get the time of my machine Or get search suggestion and latest updates.




Tagged: