How can I get my computer date ?

How can I get my computer date ?

How can I get application path ?

[78 byte] By [haryantoiguna] at [2007-11-27 10:54:00]
# 1

Double posted and answered.

http://forum.java.sun.com/thread.jspa?threadID=5196039

jverda at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 2

Date date = new Date();

That will give you the current date and time. That however has been replaced by Calendar, I believe.

To get the application path, for what? The classpath?

You can get the file path of any loaded class, interface, or library.

To determine the path for an external application, though would simply be the path to the Main class.

watertownjordana at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 3

> That

> however has been replaced by Calendar, I believe.

Absolutely not.

jverda at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 4

Or you can use: Date date = Calendar.getInstance().getTime()

I tend to store dates and times in Calendar variables rather than Date as a lot of the methods for manipulation in Date are deprecated.

And you can then always just use the getTime() method for getting a Date object from your Calendar object

c0demonk3ya at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 5

hi,

I hope this class will give u a basic date getting and the next class allows u to format with SimpleDateFormat Class.

import java.util.*;

public class Now {

public static void main(String arg[]) {

/*

** on some JDK, the default TimeZone is wrong

** we must set the TimeZone manually!!!

**Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));

*/

Calendar cal = Calendar.getInstance(TimeZone.getDefault());

String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

java.text.SimpleDateFormat sdf =

new java.text.SimpleDateFormat(DATE_FORMAT);

/*

** on some JDK, the default TimeZone is wrong

** we must set the TimeZone manually!!!

**sdf.setTimeZone(TimeZone.getTimeZone("EST"));

*/

sdf.setTimeZone(TimeZone.getDefault());

System.out.println("Now : " + sdf.format(cal.getTime()));

}

}

Here some formatting possibilities available through the SimpleDateFormat class.

import java.util.*;

import java.text.*;

public class ShowToday {

public static void main(String args[]) {

ShowToday st = new ShowToday();

st.demo();

}

public void demo() {

System.out.println(easyDateFormat("dd MMMMM yyyy"));

System.out.println(easyDateFormat("yyyyMMdd"));

System.out.println(easyDateFormat("dd.MM.yy"));

System.out.println(easyDateFormat("MM/dd/yy"));

System.out.println(easyDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z"));

System.out.println(easyDateFormat("EEE, MMM d, ''yy"));

System.out.println(easyDateFormat("h:mm a"));

System.out.println(easyDateFormat("H:mm:ss:SSS"));

System.out.println(easyDateFormat("K:mm a,z"));

System.out.println(easyDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa"));

}

public String easyDateFormat (String format) {

Date today = new Date();

SimpleDateFormat formatter = new SimpleDateFormat(format);

String datenewformat = formatter.format(today);

return datenewformat;

}

}

About Application path :

Where did you save your file. Go to that location then look at your address bar, that's where your application path.

Anyway, that's manual way.

this class let's you to get application path using a java code.

//write a class... with import and the rest..

//add this in the body as the method. m sure it will help

System.getProperties("user.dir");

null

ArchiEnger.711a at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 6

System.getProperties("user.dir");

is not the application path, unless you cd there before executing the java command. Which is also the case on Windows when double clicking a jar icon (AFAIK) and, possibly, when starting with a Startmenu item (on windows).

But that may not be the case when starting with any other kind of shortcut that may have been moved from the original location (on windows), and definately not the case when using the java command from the terminal when your current working directory is not directly above the root of the classpath.

That variable is the "current working directory", not the application path.

masijade.a at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 7

please send me your email address, I just studied java last week so I want to ask you a lot of question if you don't mind.

Thank you

haryantoiguna at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 8

please send me your email address, I just studied java last week so I want to ask you a lot of question if you don't mind.

Thank you

haryantoiguna at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...
# 9

Hey..

That's bit confusing.. there're many have posted answeres for you.

So whose email you want?

mine ;) hehehe.. I guess this is the best way to ask questions, use this forum please. Because I'm online here almost everytime than emails. You can post, if I answer you right, I still can get duke stars..

=) so can you!

Regards.

ArchiEnger.711a at 2007-7-29 11:47:31 > top of Java-index,Java Essentials,New To Java...