Conversion between String and GregorianCalendar

I have the following data in a text file which later I will Scanner in.

17-Mar-2006 1100 1280
16-Jan-2002 1120 1230
15-Jun-2003 1140 1900

I’m building this data as an “Stockmarket” object.
The instance variable “date” is declared as GregorianCalendar.
The constructor, String dt, should expect the form “dd-MMM-yyyy” in String.
Same goes to the public String date(), it should return a string of the form”dd-MMM-yyyy”.
What is the best way to convert between String and GregorianCalendar to get the job done? Thanks!

public class Stockmarket{
    // instance variables
    private GregorianCalendar date; 
    private double opening;
    private double closing; 

    public Stockmarket(String dt, double opening, double closing);  *** Can't convert from String to GregorianCalendar.
    public String date(){

        return date; *** Can't convert from GregorianCalendar to String.

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.