Hi,
Friends this is shanker...
Can anybody please post me the java code which can store the system time when click on some button...
| |
|
Welcome to KnowledgeSutra - Dear Guest | |
Log In
Started by shanker7, Jun 30 2011 02:43 PM
1 reply to this topic
#2
Posted 24 August 2011 - 10:58 PM
You ought to look up the Java API documentation to learn to do this. According to the API documentation, the java.util.Date constructor "initializes it so that it represents the time at which it was allocated," which means that you can do something like this: java.util.Date dt1 = new java.util.Date();
Put the constructor call in an action handler for a button, declare the variable as a member variable of the class, and if you need to display the date anywhere, call the toString() method on the date object. If you want to have more control over how the date is displayed, take a look at the java.text.DateFormat class and, more specifically, the format method of the DateFormat class. You can also build the date string by obtaining the date parts using the java.util.Calendar class. The Calendar.get method takes a parameter that you can specify as "java.text.Calendar." followed by DAY_OF_MONTH, MONTH, YEAR, HOUR_OF_DAY, MINUTE, SECOND.
Use the auto-complete of your Java IDE to help you with finding the other methods for the Date and Calendar classes.
Put the constructor call in an action handler for a button, declare the variable as a member variable of the class, and if you need to display the date anywhere, call the toString() method on the date object. If you want to have more control over how the date is displayed, take a look at the java.text.DateFormat class and, more specifically, the format method of the DateFormat class. You can also build the date string by obtaining the date parts using the java.util.Calendar class. The Calendar.get method takes a parameter that you can specify as "java.text.Calendar." followed by DAY_OF_MONTH, MONTH, YEAR, HOUR_OF_DAY, MINUTE, SECOND.
Use the auto-complete of your Java IDE to help you with finding the other methods for the Date and Calendar classes.
Reply to this topic

1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users













