Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Gregorian Calender Year

Posted on 2006-05-20
14
Medium Priority
?
209 Views
Last Modified: 2010-03-31
Hi,

Everytime i get a my gregcalendar.year it comes up as '6'
How do i make it show the full year.. i.e 2006 or 1999
0
Comment
Question by:jedistar
  • 6
  • 5
  • 3
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16724031
You need to use a DateFormat with yyyy
0
 

Author Comment

by:jedistar
ID: 16724037
example?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 800 total points
ID: 16724044
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(df.format(cal.getTime()));
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 16724060
0
 

Author Comment

by:jedistar
ID: 16724063
Let me rephrase my question.. i wish to compare a date in gregorian format
to a date in my db which is in varchar format.

how do i do this

(points up to 400)
0
 

Author Comment

by:jedistar
ID: 16724064
using select sql
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16724065
Please show how your varchar dates look
0
 

Author Comment

by:jedistar
ID: 16724067
30/1/6

30th jan 2006
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16724073
DateFormat df = new SimpleDateFormat("MM/d/y");
java.util.Date fromDb = df.parse(resultSet.getString("DateCol"));
boolean dbLater = fromDb.after(otherDate);
0
 
LVL 92

Expert Comment

by:objects
ID: 16724080
following shows you how to parse a date

http://javaalmanac.com/egs/java.text/ParseDate.html?l=rel

you could also use a PreparedStatement and do the comparison directly in the query
that would save you havin g to bother with parsing altogether
0
 

Author Comment

by:jedistar
ID: 16724158
How do i compare if a gregoraion date is equal to another greg date?

How do i convert a greg date to the above MM/D/Y
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16724162
boolean equalDates = date1.equals(date2);
0
 
LVL 92

Accepted Solution

by:
objects earned 800 total points
ID: 16724169
> How do i compare if a gregoraion date is equal to another greg date?

http://java.sun.com/j2se/1.5.0/docs/api/java/util/GregorianCalendar.html#equals(java.lang.Object)

> How do i convert a greg date to the above MM/D/Y

See the link I posted above for examples of formatting dates
You can get the Date instance from the Calendar using its getTime() method

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html#getTime()
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16724220
:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question