Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10152 > unrolled thread

Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string?

Started bySvenfischer2@email.com (Sven Fischer)
First post2011-11-21 16:58 +0000
Last post2011-11-21 10:25 -0800
Articles 7 — 6 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? Svenfischer2@email.com (Sven Fischer) - 2011-11-21 16:58 +0000
    Re: Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? jlp <jlp@jlp.com> - 2011-11-21 18:40 +0100
      Re: Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? jlp <jlp@jlp.com> - 2011-11-21 18:45 +0100
        Re: Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? Lew <lewbloch@gmail.com> - 2011-11-21 14:12 -0800
    Re: Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-21 17:41 +0000
    Re: Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? Mayeul <mayeul.marguet@free.fr> - 2011-11-21 19:17 +0100
    Re: Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string? Roedy Green <see_website@mindprod.com.invalid> - 2011-11-21 10:25 -0800

#10152 — Easiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string?

FromSvenfischer2@email.com (Sven Fischer)
Date2011-11-21 16:58 +0000
SubjectEasiest/shortest way to get day of week (e.g. MON) from "dd.mm.yyyy" string?
Message-ID<4eca833c$0$6571$9b4e6d93@newsspool3.arcor-online.net>
Assume I have a date as a string with the pattern "dd.mm.yyyy".

What is the easiest/shortest way to get the day of week (e.g. "MON" for Monday)
from this date?

Sven

[toc] | [next] | [standalone]


#10153

Fromjlp <jlp@jlp.com>
Date2011-11-21 18:40 +0100
Message-ID<4eca8d1a$0$2507$ba4acef3@reader.news.orange.fr>
In reply to#10152
Le 21/11/2011 17:58, Sven Fischer a écrit :
> Assume I have a date as a string with the pattern "dd.mm.yyyy".
>
> What is the easiest/shortest way to get the day of week (e.g. "MON" for Monday)
> from this date?
>
> Sven
>
  create a Calendar object with the date and Calendar.get( DAY_OF_WEEK)
return 0 for SUNDAY, 1 for MONDAY ...

-- 
Cordialement
Jean-Louis Pasturel

[toc] | [prev] | [next] | [standalone]


#10155

Fromjlp <jlp@jlp.com>
Date2011-11-21 18:45 +0100
Message-ID<4eca8e1c$0$2507$ba4acef3@reader.news.orange.fr>
In reply to#10153
Le 21/11/2011 18:40, jlp a écrit :
> Le 21/11/2011 17:58, Sven Fischer a écrit :
>> Assume I have a date as a string with the pattern "dd.mm.yyyy".
>>
>> What is the easiest/shortest way to get the day of week (e.g. "MON"
>> for Monday)
>> from this date?
>>
>> Sven
>>
> create a Calendar object with the date and Calendar.get( DAY_OF_WEEK)
> return 0 for SUNDAY, 1 for MONDAY ...
>
Sorry SUNDAY is 1, MONDAY 2 ....

-- 
Cordialement
Jean-Louis Pasturel

[toc] | [prev] | [next] | [standalone]


#10167

FromLew <lewbloch@gmail.com>
Date2011-11-21 14:12 -0800
Message-ID<31270747.678.1321913566925.JavaMail.geo-discussion-forums@prnv30>
In reply to#10155
jlp wrote:
> jlp a écrit :
>> Sven Fischer a écrit :
>>> Assume I have a date as a string with the pattern "dd.mm.yyyy".
>>>
>>> What is the easiest/shortest way to get the day of week (e.g. "MON"
>>> for Monday)
>>> from this date?
>>>
>> create a Calendar object with the date and Calendar.get( DAY_OF_WEEK)
>> return 0 for SUNDAY, 1 for MONDAY ...
>>
> Sorry SUNDAY is 1, MONDAY 2 ....

The numeric value is immaterial.

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#10154

FromAndreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Date2011-11-21 17:41 +0000
Message-ID<slrnjcl3a0.fvg.avl@gamma.logic.tuwien.ac.at>
In reply to#10152
Sven Fischer <Svenfischer2@email.com> wrote:
> Assume I have a date as a string with the pattern "dd.mm.yyyy".
> What is the easiest/shortest way to get the day of week (e.g. "MON" for Monday)
> from this date?

Look at java.text.SimpleDateFormat  (for parsing the string)
and at  java.util.Calendar          (for extracting the day of week)

[toc] | [prev] | [next] | [standalone]


#10156

FromMayeul <mayeul.marguet@free.fr>
Date2011-11-21 19:17 +0100
Message-ID<4eca94aa$0$18836$426a74cc@news.free.fr>
In reply to#10152
On 21/11/2011 17:58, Sven Fischer wrote:
> Assume I have a date as a string with the pattern "dd.mm.yyyy".
>
> What is the easiest/shortest way to get the day of week (e.g. "MON" for Monday)
> from this date?
>
> Sven
>

If you ask me the /simplest/ way to do that is with two SimpleDateFormats:
- one to parse the pattern to a Date,
- the other just to format the Date to corresponding day of the week.

Then some toUpperCase(Locale.US) to obtain MON instead of Mon.
Forcing the second SimpleDateFormat to Locale.US might be preferable.

Sounds lazy, probably quite inefficient, and is not flexible at all.
But it is a three-liners, with very short lines.

--
Mayeul

[toc] | [prev] | [next] | [standalone]


#10157

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-11-21 10:25 -0800
Message-ID<er5lc7po6smlsspm2mbr9tjqo2td261a4f@4ax.com>
In reply to#10152
On 21 Nov 2011 16:58:36 GMT, Svenfischer2@email.com (Sven Fischer)
wrote, quoted or indirectly quoted someone who said :

>Assume I have a date as a string with the pattern "dd.mm.yyyy".
>
>What is the easiest/shortest way to get the day of week (e.g. "MON" for Monday)
>from this date?

see http://mindprod.com/jgloss/calendar.html
for the usual methods.
See http://mindprod.com/products1.html#BIGDATE
for the easy way.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
I can't come to bed just yet. Somebody is wrong on the Internet. 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web