Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

start time and end time

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i m using thing code to check start time and end time of user is this a correct approach ?





       OffsetTime currentTime = OffsetTime.now();
       
       
       OffsetTime setTime=OffsetTime.parse("04:00:00.000+05:00");
       
       System.out.println(currentTime);
       
             System.out.println(setTime);
       
       System.out.println(currentTime.isBefore(setTime));

       System.out.println(currentTime.isAfter(setTime));
       
       
       String request=JOptionPane.showInputDialog(null, "I want to quit work");
       
       if(request.equals("y")){
       
       if(currentTime.isAfter(setTime))
       
               System.out.println("you are granted to leave");
       
       
       
       }
       else if(currentTime.isBefore(setTime)){
        System.out.println("its working hours");
       
       }
 
 
Rancher
Posts: 3849
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That seems reasonable so far.  Are you seeing any problem?  Is there something specific you're wondering about?  

Is the time zone something you care about here?  Do you need to be comparing people in different time zones?  I feel like if you're talking about "working hours", you might just want to use LocalTime, not OffsetTime.  Then you can ignore time zones.  But that's just a guess.
 
Master Rancher
Posts: 4284
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

code to check...


What does "to check" mean?  What tests is the code supposed to make? Should there be any results from the checks?

Please edit the code and wrap it in code tags:  select code and press Code button
 
obaid abbassi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
everything is ok how to put am and pm in this  time to compare because this code does not recognizing whether its morning 4:00  or evening 4:00
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic