Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2007, 06:24 PM
Member
 
Join Date: Nov 2007
Posts: 25
carderne is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-04-2007, 07:49 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
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); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-04-2007, 08:15 PM
Member
 
Join Date: Nov 2007
Posts: 25
carderne is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-04-2007, 09:17 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
private String space(int n) { String s = ""; for(int j = 0; j < n; j++) s += " "; return s; }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-05-2007, 10:19 AM
Member
 
Join Date: Nov 2007
Posts: 25
carderne is on a distinguished road
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:

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]);
I had to add checks earlier in the program to add/remove extra tabs depending on the length of the word...

Thanks for your help
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-05-2007, 10:34 AM
Member
 
Join Date: Nov 2007
Posts: 25
carderne is on a distinguished road
Oops. Sorry, my bad. Thinking like a idiot. Just needed to minus the word length from the max length to get the int parameter.
Shot!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello, first time here. ludragon Introductions 2 01-03-2008 06:03 AM
Method execution time javaplus Advanced Java 3 11-26-2007 10:51 AM
DataObject with the time given by me garinapavan New To Java 2 08-07-2007 07:33 PM
Time restricted method toby New To Java 1 08-07-2007 06:54 AM
method not abstract, does not override actionperformed method. Theman New To Java 1 05-08-2007 07:13 AM


All times are GMT +3. The time now is 03:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org