• 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

Date calculation

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to find date ( probably in long) of 7 days before today?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out java.util.Calendar.

Or simply do some math on the long value.
 
auvrm papu
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,
Can someone please elaborate on how do I go about doing calculations in Long?

For Ex: 1227306791752
this should pretty much represent Nov 21, 2008 around 4.33 pm

But I don't understand how those numbers are represented
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But I don't understand how those numbers are represented



Well, it's your data!! You have to tell us how it is represented !! Different systems have different representations.


Now, if this is the same as the long that is returned from the System clas, then the value is "the difference, measured in milliseconds, between the [represented] time and midnight, January 1, 1970 UTC".

Henry
 
auvrm papu
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used the following

[ November 21, 2008: Message edited by: Ais Kaly ]
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ais Kaly:
I used the following



That's the same representation as the System class. It's the current time, measured in milliseconds, from January 1st, 1970 UTC.

So, to subtract a week, just subtract a week's worth of milliseconds.

Henry
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I object!

Usually subtracting a week's worth of milliseconds is not a problem. However, there is this nasty thing called "daylight savings time", that once a year makes a day 23 hours and once a year 25 hours. This makes the calculation inaccurate if the hours is before 1 am or after 11 pm.

I'll second Bear's recommendation of Calendar:
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. 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