Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Diem Tran   on Mar 27 In Java Category.

  
Question Answered By: Midissia Lopez   on Mar 27

Well if the date  is just a string then just use
java.lang.String.split(). ie.

String dt = "01-23-2004";
String dateParts[] = dt.split("-");
String month  = dateParts[0];
String day  = dateParts[1];
String year = dateParts[2];

If you're using an actual "Date" class like java.util.Date or
java.sql.Date then you can use the java.util.Calendar class to get the
pieces of the date. ie.

Date dt;
.
.
.
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DATE);
int year = cal.get(Calendar.YEAR);

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on how to split a date value? Or get search suggestion and latest updates.


Tagged: