Results 1 to 7 of 7
- 04-02-2011, 12:16 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 93
- Rep Power
- 0
Is there a Java function which retrieves todays name (e.g. Friday) from the OS?
I'm writing a GUI program which draws tick for how many days you've run the program consecutively.
So if i first run it on sunday, it will show one tick. If i run it again on monday, two ticks. If i skip a day and run it on wednesday, it will start over and show one tick, because monday and wednesday aren't consecutive.
Yesterday I wrote some 150 lines of code to make three combo boxes: day, month and year so that the user can enter a date and the program calculates what day is today and writes it to a file.
I wanted to do that for the sake of practice. But now i want to know, for the sake of knowledge, could I have used some java function which would automatically retrieve todays day from the Operating System?
- 04-02-2011, 12:21 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Have a look at the DateFormat class or the SimpleDateFormat class.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-02-2011, 12:49 PM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
you can use this
S=7 in Saturday. that means week starts with SundayJava Code:GregorianCalendar cal = new GregorianCalendar(); //Create calendar int s=cal.get(GregorianCalendar.DAY_OF_WEEK);
- 04-02-2011, 01:02 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
- 04-02-2011, 01:12 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 93
- Rep Power
- 0
Thanks Josah, i'll have a look at that.
Last edited by eLancaster; 04-02-2011 at 01:14 PM.
- 04-02-2011, 01:15 PM #6
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Don't Forget to try yourself before asking others help.....
Press REP, if you find their advices/solutions effective.
- 04-02-2011, 01:49 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
That is a very bad and hackish 'solution' (mind the quotes); for one thing you lose all localization and for another: you don't know whether or not those numbers lie in the range [1 ... 7]. The Calendar class doesn't have symbolic constants for no reason. Don't do what you just did.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
php function to java
By thorbcn in forum New To JavaReplies: 2Last Post: 07-04-2011, 12:40 AM -
Calling function in Javascript- from other function
By jdigger in forum New To JavaReplies: 1Last Post: 02-27-2011, 09:00 PM -
Friday night java puzzle
By niu_niu in forum New To JavaReplies: 12Last Post: 06-19-2010, 10:54 PM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
help with function in java!!!!
By ricky in forum New To JavaReplies: 6Last Post: 10-12-2009, 01:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks