tags:

views:

659

answers:

8

i am searching code in java for fetching or synchronising my local PC system time into my application

+1  A: 

Not really sure about what you meant, but you probably just need

Date d = new Date();
Raibaz
+6  A: 

Both

new java.util.Date()

and

System.currentTimeMillis()

will give you current system time.

sleske
+1  A: 

Like said above you can use

Date d = new Date();

or use

Calendar.getInstance();

or if you want it in millis

System.currentTimeMillis()
Nuno Furtado
A: 

Java Date Time

Chathuranga Chandrasekara
+1  A: 

To get system time use Calendar.getInstance().getTime()

And you should get the new instance of Calendar each time to have current time.

To change system time from java code you can use a command line

Alex
+1  A: 

You can use new Date () and it'll give you current time.

If you need to represent it in some format (and usually you need to do it) then use formatters.

DateFormat df = DateFormat.getDateTimeInstance (DateFormat.MEDIUM, DateFormat.MEDIUM, new Locale ("en", "EN"));
String formattedDate = df.format (new Date ());
Roman
+1  A: 

System.currentTimeMillis()

everything else works off that.. eg new Date() calls System.currentTimeMillis().

mP
+5  A: 

Try this:

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class currentTime {

    public static void main(String[] args) {
     Calendar cal = Calendar.getInstance();
     cal.getTime();
     SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
     System.out.println( sdf.format(cal.getTime()) );
    }

}

You can format SimpleDateFormat in the way you like. For any additional information you can look in java api:

SimpleDateFormat

Calendar

Artur