Results 1 to 6 of 6
Thread: Time method
- 11-04-2007, 05:24 PM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
Time method
I'm busy writing a program that creates a database of all you songs and movies.
It displays your songs in a list with Track name, Artist, Album and date added. I could have it so that it asks the date each time, but this is a bit tedious, so I was wondering which method I could use to get the date and store as a String...
A bit example code explaining it would be great.
Thanks
- 11-04-2007, 06:49 PM #2
Java Code:import java.util.*; import java.text.*; public class GettingTheDate { public static void main(String[] args) { DateFormat df = new SimpleDateFormat("dd MMM yyyy"); Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); String toStore = df.format(now); System.out.printf("now = %s%ntoStore = %s%n", now, toStore); } }
- 11-04-2007, 07:15 PM #3
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
Ok. sweet. Thanks for your help. That should do it. And just one more little question. When I output the songs in columns (currently just using System.out.println), is there any way besides tabs to keep the words properly lined up? I've had to make checks that add extra tabs if the words are below a certain length... Thanks again
- 11-04-2007, 08:17 PM #4
Java Code:private String space(int n) { String s = ""; for(int j = 0; j < n; j++) s += " "; return s; }
- 11-05-2007, 09:19 AM #5
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
Ok, thanks. But then I still have to specify how long I want the spaces to be. Here's my code for the output part:
I had to add checks earlier in the program to add/remove extra tabs depending on the length of the word...Java Code:System.out.println("\n\n\n#\tTrack\t\t\tArtist\t\t\tAlbum\t\t\tDate Added\n------------------------------------------------------------------------------------------"); for (int i = 0; i <= songNum; i++) System.out.println(i + "\t" + song[i][0] + "\t\t\t" + song[i][1] + "\t\t\t" + song[i][2] + "\t\t\t" + song[i][3]);
Thanks for your help
- 11-05-2007, 09:34 AM #6
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
Similar Threads
-
method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03-26-2010, 05:12 PM -
Hello, first time here.
By ludragon in forum IntroductionsReplies: 2Last Post: 01-03-2008, 05:03 AM -
Method execution time
By javaplus in forum Advanced JavaReplies: 3Last Post: 11-26-2007, 09:51 AM -
DataObject with the time given by me
By garinapavan in forum New To JavaReplies: 2Last Post: 08-07-2007, 06:33 PM -
Time restricted method
By toby in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks