• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Date formatting and time calculations.

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Need to do the following.
1) convert string date in specific format (ex. "04-30-2003 12:50:47") to unix time
2) subtract off one month - I got that part, lol.
3) convert the new unix time back to date in same specific format as original in step 1.
I have been unable to do this even though it seems like it should be straight forward. I am confused on what classes I should be using.
Thanks for the help!
Rob
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to use a SimpleDateFormat with the pattern "MM-dd-yyyy hh:mm:ss". The good news is it will do both the parsing and the reformatting for you. Actually it parses the String into java.util.Date, but it's trivially easy to get the long integer representation from that. Remember, it's similar to Unix (same epoch), but it's a signed 64 bit integer expressing the time in milliseconds, not seconds.
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Greg!
 
reply
    Bookmark Topic Watch Topic
  • New Topic