• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Formatting Todays Date

 
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use data from a remote iSeries server.
Some of the date fields are in this format 1240528.
This was done during the Y2K era.

I need to format the following into 1yyMMdd.

 
Sheriff
Posts: 4641
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this should work:DateTimeFormatter
 
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That works for the title of the thread "today", but reading the post, looks like more work needed to convert that numeric format to something usable that Java understands.

Questions:

I'm not understanding how that numeric format is supposed to be parsed, is this more about how to convert that number to something usable? Some format specific to "iSeries"? (Which I'm not familiar with but maybe someone here is.)


These may not matter but I already typed them (lol)...

Are they supposed to be date/time or just date?

What timezone is this data stored in?
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Follow up - is the length of that example number a realistic length?

Because if it's longer it's possible/probable that it's just a standard "Unix" time in seconds. Which would make this pretty easy. This 1240528 looks too short for that (but maybe you just random typed that for an example)...
 
Ron McLeod
Sheriff
Posts: 4641
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Hamers wrote:This 1240528 looks too short for that (but maybe you just random typed that for an example)...


It sounds like this for input into a legacy system where their fix for Y2K  was to prepend the date with a century indicator - 0=19XX, 1=20XX.
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yuck.. maybe though. I'm still not sure how to parse the rest of that number though if it's just month/day.

It doesn't seem long enough to include time either (assuming it's a real example and not just something randomly typed for an example).
 
Master Rancher
Posts: 5060
81
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1240528 is not a random example - it's today's date, 2024-05-28, formatted according to the format given in the original post, 1yyMMdd.  It contains no time info, only date.  This can be reversed to parse a given string as a LocalDate, e.g.
 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Hamers wrote:Yuck.. maybe though. I'm still not sure how to parse the rest of that number though if it's just month/day.

It doesn't seem long enough to include time either (assuming it's a real example and not just something randomly typed for an example).



1240528 is a real field value.

Rob M. was correct 1 = 20XX
24 = year
05 = Month
28 = Day
 
Lou Hamers
Bartender
Posts: 303
12
IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see now, you wanted today's date in that legacy format. I should have caught onto that earlier. I'll blame it on tiredness.
 
Saloon Keeper
Posts: 10929
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:1240528 is a real field value.

Rob M. was correct 1 = 20XX
24 = year
05 = Month
28 = Day


Do you ever have the case where the '1' is missing or replaced by a different digit?
 
Mike Simmons
Master Rancher
Posts: 5060
81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If they ever use 0 for 1900s, or 2 for 2100s, then one approach would be to take that original format as a decimal number, and add 19000000.

So 1240528 + 19000000 = 20240528.  Convert that back to a String and parse it using yyyyMMdd.  That way you can easily handle any date from 1900 on to... whenever, really.
 
Carey Brown
Saloon Keeper
Posts: 10929
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:If they ever use 0 for 1900s, or 2 for 2100s, then one approach would be to take that original format as a decimal number, and add 19000000.

So 1240528 + 19000000 = 20240528.  Convert that back to a String and parse it using yyyyMMdd.  That way you can easily handle any date from 1900 on to... whenever, really.


Yes. I'm  asking "IF?".
 
Sheriff
Posts: 28323
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Yes. I'm  asking "IF?".

So far the question is only about today's date, though.
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:1240528 is not a random example - it's today's date, 2024-05-28, formatted according to the format given in the original post, 1yyMMdd.  It contains no time info, only date.  This can be reversed to parse a given string as a LocalDate, e.g.


That LocalDate.from(format.parse(dateStr)) can be simplified as LocalDate.parse(dateStr, format), which is shorthand for format.parse(dateStr, LocalDate::from). All three create an intermediate object that is converted to a LocalDate, but the second form is shorter and (at least for me) easiest to read.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic