LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-25-2004, 09:49 AM   #1
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quick Java question


I have a GregorianCalendar object and want to find out which day the first of a given month is. How do I go about this? I'm really stuck.

Thanx for any help.
 
Old 01-25-2004, 06:24 PM   #2
eric.r.turner
Member
 
Registered: Aug 2003
Location: Planet Earth
Distribution: Linux Mint
Posts: 216

Rep: Reputation: 31
Is this what you're looking for?

Code:
/*
 * CalendarTest.java
 *
 * Created on January 25, 2004, 5:09 PM
 */

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author  eric.r.turner
 */
public class CalendarTest {

    /*
     *  Prints which weekday the first day of the month falls on.
     */
    public void printFirstDayOfMonth( int year , int month ) {

        GregorianCalendar calendar = new GregorianCalendar( year , month , 1 );
        
        switch ( calendar.get( Calendar.DAY_OF_WEEK ) ) {
            case Calendar.SUNDAY :
                    System.out.println( "Sunday" );
                    break;
            case Calendar.MONDAY :
                    System.out.println( "Monday" );
                    break;
            case Calendar.TUESDAY :
                    System.out.println( "Tuesday" );
                    break;
            case Calendar.WEDNESDAY :
                    System.out.println( "Wednesday" );
                    break;
            case Calendar.THURSDAY :
                    System.out.println( "Thursday" );
                    break;
            case Calendar.FRIDAY :
                    System.out.println( "Friday" );
                    break;
            case Calendar.SATURDAY :
                    System.out.println( "Saturday" );
                    break;
        }
    }

    public static void main(String[] args) {
        CalendarTest ct = new CalendarTest();
        ct.printFirstDayOfMonth( 2004 , Calendar.FEBRUARY );
    }    
}

Last edited by eric.r.turner; 01-25-2004 at 06:28 PM.
 
Old 01-26-2004, 12:44 PM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Original Poster
Rep: Reputation: Disabled
Yes. Bloody hell, I'm thick.

Thank you very much .
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
samba smb.config question (quick question) TheDOGG Linux - Networking 1 03-02-2004 07:19 AM
quick question - java Laptop2250 Programming 2 10-15-2003 09:56 PM
Quick Java plug-in question Tyir Linux - Newbie 4 10-09-2003 01:58 PM
Quick question: Does Java 1.4.2 unstable in your PC? codec Linux - Software 3 09-16-2003 11:24 AM
2 Quick Java Questions Crashed_Again Programming 13 09-10-2003 04:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration