Results 1 to 9 of 9
- 08-23-2008, 11:28 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 15
- Rep Power
- 0
- 08-23-2008, 12:21 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Since you have to do a separation, better to deal with strings according to your requirements. But in later, if you rally want to deal with the Data format, you should convert it to Date/Time format too.
- 08-24-2008, 05:21 AM #3
Java Code:import java.util.*; import java.text.*; public class Test { public static void main(String[] args) { DateFormat format = new SimpleDateFormat("HH:mm dd MMM yyyy"); DateFormat timeFormat = new SimpleDateFormat("HH:mm"); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Date now = calendar.getTime(); System.out.printf("now = %s%n", format.format(now)); // Set the time for 2150. int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); calendar.set(year, month, day, 21, 50); System.out.printf("setTime = %s time = %s%n", format.format(calendar.getTime()), timeFormat.format(calendar.getTime())); } }
- 08-27-2008, 04:11 AM #4
Member
- Join Date
- Aug 2008
- Posts
- 15
- Rep Power
- 0
1)
How you get the SimpleDateFormat() constructor? I thought have to follow the name of the class which is DataFormat() when declaring?
2)
There is no Date() method in the Calendar Class. How you get it?
My Java concept of OO is still new. Thanks!
- 08-27-2008, 05:28 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 08-27-2008, 05:41 AM #6
1)How you get the SimpleDateFormat() constructor? I thought have to follow the name of the class which is DataFormat() when declaring?
Generally, yes, but DateFormat is an interface, not a class. It is implemented by the SimpleDateFormat class.
2)There is no Date() method in the Calendar Class.
Agreed.
How you get it?
The setTime method of the Calendar class takes a Date argument.
To understand these things we look at the javadocs. Being able to find your way around the docs is a key to writing java code.
Start with the Overview, look up the class/interface in the left frame, click on the link and the class api loads into the main frame. Now you can see what constructors, fields and methods are available to/in the class. Some may be inherited from superclasses.
- 08-27-2008, 06:19 AM #7
Member
- Join Date
- Aug 2008
- Posts
- 15
- Rep Power
- 0
How you know DataFormat is an interface not class?
But from the API, i am only able to find it as class not interface.
java.text
Class DateFormat
java.lang.Object
extended by java.text.Format
extended by java.text.DateFormat
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
SimpleDateFormat
-
You are actually correct and hardwired is wrong here (almost). If you at the first line of the API, it says:How you know DataFormat is an interface not class?
But from the API, i am only able to find it as class not interface.. So DateFormat is a class, but an abstract one, and as such it cannot be directly constructed itself but instead needs to be subclassed to be instantiated.Java Code:public abstract class DateFormat
- 08-27-2008, 07:06 AM #9
Similar Threads
-
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM -
How to handle each display/shell dialog box (not knowed) and choose default answer
By lenar in forum SWT / JFaceReplies: 0Last Post: 04-04-2008, 12:15 AM -
Calling a variable from main to another class
By itsme in forum New To JavaReplies: 1Last Post: 12-18-2007, 03:35 PM -
Public class variable
By Java Tip in forum Java TipReplies: 0Last Post: 12-03-2007, 09:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks