-1

My Problem: I wanted a String in which at the start of the Program, the Name of tomorrows Weekday is saved.

Basically, if I start the Program on Monday, it calls a Method and the String has the Value "Tuesday".

Is there an easy way to do it ?

michaeljoseph
  • 7,023
  • 5
  • 26
  • 27
Freund
  • 27
  • 1
  • 6
  • 2
    Please show us some code. – AKS Jul 31 '15 at 07:51
  • 3
    Hi Freund, welcome to stackoverflow (SO). SO works great if you have a specific question **and** you can show what you have already tried to solve the problem (best with an [MCVE](http://stackoverflow.com/help/mcve)). Take a look at the [SO Tour](http://stackoverflow.com/tour) and the [Help Center](http://stackoverflow.com/help) to find out [how to ask good questions](http://stackoverflow.com/help/how-to-ask). – Jens Hoffmann Jul 31 '15 at 08:11
  • @harpribot Freund is obviously new so SO, so how about being welcoming towards new joiners and help them to use SO correctly and efficiently, instead of potentially driving them off with a snappy answer. – Jens Hoffmann Jul 31 '15 at 08:14
  • @JensHoffmann I apologize for this. – harpribot Jul 31 '15 at 08:20
  • @harpribot That's OK, we all learn. Thanks for apologizing! – Jens Hoffmann Jul 31 '15 at 08:28

2 Answers2

1

If you are using Java 8 or later, you could try this using the java.time package:

    LocalDate date = LocalDate.now().plusDays(1);
    String dayName = date.getDayOfWeek().toString();

See the java.time Tutorial.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Roy James Schumacher
  • 636
  • 2
  • 11
  • 27
0

I would go with something like that (Java 8):

    LocalDateTime date = LocalDateTime.now();
    do {
        date = date.plusDays(1);
    } while(date.getDayOfWeek().getValue() >= 5);
    String nextDayName = date.format(DateTimeFormatter.ofPattern("EEEE"));

Possibly, isolate the date acceptance criteria in a separate method for easier future improvements.

dotvav
  • 2,808
  • 15
  • 31
  • Do not use `ordinal()` to obtain the numeric representation of DayOfWeek (assuming that's what you meant as `getOrdinal()` doesn't exist). Use [`getValue()`](https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html#getValue--) instead. – Jens Hoffmann Jul 31 '15 at 08:45
  • Also it is not clear if Freund actually wants to skip weekends or not. – Jens Hoffmann Aug 01 '15 at 10:13
  • @JensHoffman thanks for the tip. I wrote this answer as per my understanding and for exercising myself to the dates API of Java 8 – dotvav Aug 01 '15 at 11:50