Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: New to java, need to know how to incorparate system time into a block of code.

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New to java, need to know how to incorparate system time into a block of code.

    Hello, below is a simple block of code. I have been trying to add a println of the
    system time. I tried many examples but most start with import java.util.Calendar;
    This gets an error in eclipse stating this is never used. I tried many examples and
    get the same error with different import calls. Can someone add to my code
    example the minimum code to print out the time?


    Code
    package com.allmycode.first;
     
    public class GoodbyeMoon {
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		String var1 = "GoodbyeMoon";
    		int var2 = 10;
    		System.out.println(var1+" "+ var2);
    		String var3 = "Done";
    		System.out.println(var3);
     
     
    	}
     
    }
    Last edited by helloworld922; September 28th, 2011 at 09:34 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,243
    My Mood
    Hungover
    Thanks
    142
    Thanked 617 Times in 528 Posts

    Default Re: New to java, need to know how to incorparate system time into a block of code.

    That's not an error, it's just a warning. It's telling you that you have an import that you don't use. I don't see anything in your code that attempts to print out the time. Check out the System API for some useful functions: System (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,069
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: New to java, need to know how to incorparate system time into a block of code.

    What format do you want to time printed in?
    There are several different classes or methods that could be used.

  4. #4
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to java, need to know how to incorparate system time into a block of code.

    Quote Originally Posted by Norm View Post
    What format do you want to time printed in?
    There are several different classes or methods that could be used.
    I would like to see the time as hour min example 2:20

    Thanks

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,069
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: New to java, need to know how to incorparate system time into a block of code.

    Look at the DateFormat class.

  6. #6
    Junior Member
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to java, need to know how to incorparate system time into a block of code.

    Norm, thank you; I found a way to do it see below, not prity but it worked. The trick was the import string I tried did not work.

    package com.allmycode.first;
    import java.util.Date;

    public class GoodbyeMoon {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String var1 = "GoodbyeMoon";
    int var2 = 10;
    Date date = new Date();
    System.out.println("Today is " + date);
    System.out.println(var1+" "+ var2);
    String var3 = "Done";
    System.out.println(var3);


    }

    }

Similar Threads

  1. Having a hard time figuring out how to make my code work
    By iainnitro in forum Loops & Control Statements
    Replies: 2
    Last Post: September 6th, 2011, 07:48 AM
  2. new to java.... having a hard time trying to read code
    By Newbie_96 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 6th, 2011, 01:51 AM
  3. Java sliding block puzzle issues
    By Vesper in forum What's Wrong With My Code?
    Replies: 15
    Last Post: April 11th, 2011, 07:30 AM
  4. Creating Block cipher without the use of inbuilt java funcs
    By fortune2k in forum Algorithms & Recursion
    Replies: 0
    Last Post: November 15th, 2010, 08:43 AM
  5. Tikal Eclipse - Moving system time
    By leguin in forum Java IDEs
    Replies: 2
    Last Post: December 3rd, 2009, 12:34 AM