|
| |||||||||
| Tags: data type, date, java, jsp, manipulation, scripting language, string |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Manipulating a Date in java
Hello, I have a class attribute of type date, I can retrieve the day, month and year to date I have only seen separately in the API methods that getMonth (), etc. are no longer be used. It should (according to API) use, Calendar.get (Calendar.DAY_OF_MONTH). Can you explain how? Here is my code Code: ...
Date dt;
...
Public String toString(){
return ("Date:" + MyDate.getMonth());
...
} |
|
#2
| |||
| |||
| Re: Manipulating a Date in java
Hello, Just have a look at the sample code, it is a simple code. It will be better for your understanding. Code: GregorianCalendar foe = new GregorianCalendar(); foe.setTime( unObjetDate ); int month = foe.get(GregorianCalendar.MONTH); int year = foe.get(GregorianCalendar.YEAR); int day = foe.get(GregorianCalendar.DAY_OF_MONTH); |
|
#3
| |||
| |||
| Re: Manipulating a Date in java
Hello, I have another question, always on my dates. I get a date as "dd / MM / YYYY" (String), I must first convert the Date type (I must) and then display it separately. Here is my piece of code: Code: DateFormat dtf = new SimpleDateFormat("dd / MM / yyyy");
Date d = dtf.parse("22/03/2008");
...
GregorianCalendar geo = new GregorianCalendar();
geo.setTime(d);
int month = geo.get(GregorianCalendar.MONTH);
int year = geo.get(GregorianCalendar.YEAR);
int day = geo.get(GregorianCalendar.DAY_OF_MONTH);
...
System.out.System.out.println("Day" + + Day "Month" Month + + "Year" + Year); |
|
#4
| |||
| |||
| Re: Manipulating a Date in java
Hello, Just have a look at the following code. Code: public class Example
{
public static final String dt = "dd-MM-yyyy HH:mm:ss";
// public static String now()
//{
// Calendar c = Calendar.getInstance();
// SimpleDateFormat s = new SimpleDateFormat(dt);
// return s.format(c.getTime());
//}
public static void main(String[] args)
{
//Step1:Getting Time Zone "country"
Calendar c = Calendar.getInstance();
String tmzn = c.getTimeZone().getDisplayName();
System.out.println("tmzn is : " + tmzn );
//Step2:Getting Time in Milli Seconds
System.out.println("Current Time in MiliSeconds : " + c.getTimeInMillis() );
//Step3:Getting current time in date format
//Calendar c = Calendar.getInstance();
SimpleDateFormat s = new SimpleDateFormat(dt);
String time=s.format(c.getTime());
System.out.println(time);
// System.out.println("Now : " + Example.now());
}
} |
|
#5
| |||
| |||
| Re: Manipulating a Date in java
Hello, This is another sample code for you. Code: import java.text.SimpleDateFormat;
import java.util.Date;
public class DateExample2 {
public static void main(String[] args) {
SimpleDateFormat simdt =
new SimpleDateFormat("EEEE-MMMM-dd-yyyy");
Date dt = new Date();
System.out.println(simdt.format(dt));
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Manipulating a Date in java" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting Current Date in Java | Level8 | Software Development | 5 | 27-02-2010 05:26 PM |
| Exactly match date in java | Vodka | Software Development | 5 | 13-02-2010 02:00 AM |
| Query with Date in java | Gunner 1 | Software Development | 5 | 12-02-2010 03:55 AM |
| Find date in java | Allan.d | Software Development | 3 | 09-12-2009 10:43 AM |
| How to do the Date comparison in Java | Rock Villa | Windows Software | 3 | 06-08-2009 10:44 AM |