Results 1 to 3 of 3
  1. #1
    Fuzztional is offline Member
    Join Date
    Jan 2014
    Rep Power

    Default SimpleDateFormat Problem with return.

    Hey guys, i am currently attending a java class and i'm having some problems finding the solution to a question regarding Calendar and SimpleDateFormat.

    We're supposed to create a method which takes a Calendar-Object and returns a String holding 4 numers for year, 3 letters for a month (JAN), 1-2 numbers depending on day. They shall be seperated with a -

    This is what i have done so far;

    import java.util.GregorianCalendar;
    import java.util.Calendar;
    import java.text.SimpleDateFormat;

    public class Dt2 {
    public String cal2String(Calendar c) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MMM-dd");

    return ??
    public static void main(String [] args) {
    Calendar c = new GregorianCalendar(2014,0,31);
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyy-MMM-dd HH:mm:ss");


    I can't find the solution on how to return my method, i have tried with toString (which i think we are supposed to use) but it only gives me complilation errors

    Please help me..

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power

    Default Re: SimpleDateFormat Problem with return.

    return what you've passed to sysout in the main method.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: SimpleDateFormat Problem with return.

    Quote Originally Posted by PhHein View Post
    return what you've passed to sysout in the main method.
    Wow I had to read that three times while re-reading the code three times before I understood that one :)

    Java Code:
    System.out.println(sdf.format(c.getTime())); // sdf.format() returns the string you want (apparently)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. SimpleDateFormat()
    By ajetrumpet in forum New To Java
    Replies: 8
    Last Post: 04-02-2013, 10:48 AM
  2. SimpleDateFormat Problem
    By UnfairBear in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-12-2011, 10:50 AM
  3. Problem with SimpleDateFormat
    By johan313 in forum Advanced Java
    Replies: 3
    Last Post: 01-17-2011, 05:20 PM
  4. JTextField and SimpleDateFormat
    By mine0926 in forum New To Java
    Replies: 15
    Last Post: 07-06-2010, 03:10 AM
  5. Using SimpleDateFormat
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 07-18-2008, 08:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts