parsing date from day of week with java datetimeformatter

Mercutio

I'm parsing text from an sms service using a java program, and I see that when using DateTimeFormatter 'E' or 'e' are the pattern characters for days of the week, and that the number of chars determines type of format (i.e. 'E' = T, 'EE' = Tu, 'EEE' = Tue, etc...) but in my program I'm never sure what format the message will include.

If I'm trying to check for the day of the week, can I check for all the formats using a single pattern? If not, when I'm checking for fully written out days (which vary in character length) how many E's in a row will include both Monday (6 letters) and Wednesday (9 letters)?

for example:

String singleWordFromMessage = "thursday";
LocalDateTime potentialDate = LocalDateTime.parse(singleWordFromMessage, DateTimeFormatter.ofPattern("EEEE"));

I'm missing how that works in the docs and my searches here have not been fruitful so far. Thanks in advance for any help.

Mercutio

As @RC pointed out, I missed:

"Text: The text style is determined based on the number of pattern letters used. Less than 4 pattern letters will use the short form. Exactly 4 pattern letters will use the full form. Exactly 5 pattern letters will use the narrow form. "

So the pattern "EEEE" would format to the day's full name, regardless of length. The patterns do not seem to support multiple types, but the same can be achieved by stripping the string to just the 'short' or 'narrow' day.

Thanks for all the help.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Take day of week from date

From Dev

JAVA Find day of the week from user entered date

From Dev

Java Time's week-of-week-based-year pattern parsing with DateTimeFormatter

From Dev

Using new Java 8 DateTimeFormatter to do strict date parsing

From Dev

Parsing date and time with the new java.time.DateTimeFormatter

From Java

Java DateTimeFormatter is not parsing as expected

From Dev

Parsing a date using DateTimeFormatter ofPattern

From Dev

BIDS\SSIS Derived day of week from date

From Dev

Get the day of the week from a date using Jquery?

From Dev

Printing day of the week from exact date in bash

From Dev

Displaying the Day Of The Week From Date Picker

From Dev

substract the week day from a date in Hive SQL

From Dev

Joda - DateTimeFormatter - print day of a week as a shortcut

From Java

Python - Get date from day of week, year, and week number

From Dev

php: Calculate Date from Week of Year and Day of Week

From Dev

Get Date in Java given Week number, week day and year

From Dev

Java DateTimeFormatter start week with Monday

From Java

Java DateTimeFormatter parsing with special characters

From Dev

Sort by day of the week from Monday to Sunday in Java

From Dev

Order date by day of the week

From Dev

Translating date to day of week

From Dev

Parsing date from XML with Java

From Dev

get day of week from returned date from server

From Dev

Parsing date without month using DateTimeFormatter

From Dev

Android get Day of week from date returns different values for the same day of week

From Dev

Android get Day of week from date returns different values for the same day of week

From Dev

Get day string from day of week integer java

From Dev

Get day string from day of week integer java

From Dev

How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?

Related Related

  1. 1

    Take day of week from date

  2. 2

    JAVA Find day of the week from user entered date

  3. 3

    Java Time's week-of-week-based-year pattern parsing with DateTimeFormatter

  4. 4

    Using new Java 8 DateTimeFormatter to do strict date parsing

  5. 5

    Parsing date and time with the new java.time.DateTimeFormatter

  6. 6

    Java DateTimeFormatter is not parsing as expected

  7. 7

    Parsing a date using DateTimeFormatter ofPattern

  8. 8

    BIDS\SSIS Derived day of week from date

  9. 9

    Get the day of the week from a date using Jquery?

  10. 10

    Printing day of the week from exact date in bash

  11. 11

    Displaying the Day Of The Week From Date Picker

  12. 12

    substract the week day from a date in Hive SQL

  13. 13

    Joda - DateTimeFormatter - print day of a week as a shortcut

  14. 14

    Python - Get date from day of week, year, and week number

  15. 15

    php: Calculate Date from Week of Year and Day of Week

  16. 16

    Get Date in Java given Week number, week day and year

  17. 17

    Java DateTimeFormatter start week with Monday

  18. 18

    Java DateTimeFormatter parsing with special characters

  19. 19

    Sort by day of the week from Monday to Sunday in Java

  20. 20

    Order date by day of the week

  21. 21

    Translating date to day of week

  22. 22

    Parsing date from XML with Java

  23. 23

    get day of week from returned date from server

  24. 24

    Parsing date without month using DateTimeFormatter

  25. 25

    Android get Day of week from date returns different values for the same day of week

  26. 26

    Android get Day of week from date returns different values for the same day of week

  27. 27

    Get day string from day of week integer java

  28. 28

    Get day string from day of week integer java

  29. 29

    How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?

HotTag

Archive