Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Date and Time Exercise

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Date and Time Exercise

    I need a date and time to be added to GUI interface.

    Date and time has to throw an error for working hours.

    Time must be 24 hour format.
    Day must be name of day, date and month.

    I have a Jdate chooser and time picker but I can’t add my own code to the source.
    Text fields I can’t seem to get to work for date and time.

    Must be for netbeans in Java

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Date and Time Exercise

    What have you tried?
    Be sure to wrap all posted code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Date and Time Exercise

    import java.text.SimpleDateFormat;
    import java.util.Date;
    class TestDates_Format {
    public static void main(String args[]) {
    Date objDate = new Date(); // Current System Date and time is assigned to objDate
    System.out.println(objDate);
    String strDateFormat = "hh:mm:ss a dd-MMM-yyyy"; //Date format is Specified
    SimpleDateFormat objSDF = new SimpleDateFormat(strDateFormat); //Date format string is passed as an argument to the Date format object
    System.out.println(objSDF.format(objDate)); //Date formatting is applied to the current date
    }
    }

    --- Update ---

    This gives me the Date and time - now I want to put in the following constraints :

    If the order time is before : 9:00 am or after 22:00 pm - Monday to Saturday or before 8:00am and after at 21:00pm on Sundays.
    I want to display an "error" that Says we are closed for orders.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Date and Time Exercise

    Here is a link to a site showing how to compare dates: https://mkyong.com/java/how-to-compare-dates-in-java/

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Aug 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Date and Time Exercise

    Thanks I will give it try and let you know - appreciate your feedback.

Similar Threads

  1. current date and time
    By Nix in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 9th, 2017, 11:52 AM
  2. Splitting date string by date and time and assigning it to 2 variables
    By KaranSaxena in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 17th, 2014, 05:58 AM
  3. date and time
    By gautammuktsar@gmail.com in forum Java Servlet
    Replies: 1
    Last Post: April 16th, 2014, 10:02 AM
  4. Using Date() to get Start Time and Finish Time of a copyFiles method
    By dalythe in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 17th, 2013, 09:50 PM
  5. Parsing a full date/time/timezone date to "yyyy-MM-dd"
    By Occidentally in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 4th, 2012, 08:57 AM