Sponsored Content
Full Discussion: Java Date Class
Top Forums Programming Java Date Class Post 302924379 by totoro125 on Saturday 8th of November 2014 11:19:46 PM
Old 11-09-2014
Java Date Class

I am looking at a website to learn Java and this is one of the exercises.

Write a program that will show different time and date information based on what number you send it. The codes are:

0 - number of milliseconds since January 1, 1970

1 - number of seconds since January 1, 1970

2 - number of days since January 1, 1970

3 - current date and time

So if I type: java prob 2
I want to see: days since January 1, 1970: 10727

I started it and used a switch statement. I am pretty sure I need to use the Date class in some way but I do not know how to put it together. If someone can show me how to do one, that would be very helpful.

Code:
public class prob4
 {
    public static void main(String args[])
    {
      String ArgumentFromCommandLine = args[0];
	  int time = Integer.parseInt(ArgumentFromCommandLine);    

        switch ( time )
    {
        case 0:
            ???;
            break;
        case 1:
            ???;
            break;
        case 2:
            ???;
            break;
        case 3:
            ???;
            break;
        default:
            System.out.println("Invalid");
    }
	
    }

}

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running java class with a cron

Hello everybody, I have a problem about running a java class with a cron : I have Cron.txt file which has : 0,5,10,15,20,25,30,35,40,45,50,55 * * * * CronJava.txt I have CronJava.txt wihich has : cd ias/j2ee/SapAktarim/applications/SapAktarim/SapAktarim/WEB-INF/classes/;java -classpath... (3 Replies)
Discussion started by: UBGandalf
3 Replies

2. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies

3. Shell Programming and Scripting

call constructor of java class in script

Hi, Is it possible to call the constructur of a java class in a shell script? I know you can call static methods, but can you also call the constructor? tnx. (1 Reply)
Discussion started by: thebladerunner
1 Replies

4. Fedora

Help, how to dynamicly load java class

Hi, everyone: I'm trying to connect to DB using JDBC on fedora. I have successfully installed jdk and it's ok to run common java program. The environment variables: JAVA_HOME=/installed/mycoy/jdk1.6.0 PATH=$JAVA_HOME/bin:$PATH... (3 Replies)
Discussion started by: mycoy
3 Replies

5. Programming

how abstract class differs in Java and C++?

hello all, i want to know if there is any difference in working and syntax declaration of abstract class in Java and C++. (1 Reply)
Discussion started by: haravivar
1 Replies

6. Programming

Help in JAVA main and class

Is anyone know how to write a class in separate file? While method does it needs to be contained in a printwriter class? Can I have the format of the printwriter class as a reference? Thanks a lot. (1 Reply)
Discussion started by: eel
1 Replies

7. Programming

Link array to class java

Hi, I need help to Link array from one class to another class Firstly CSVParser Class what it did is load csv file and store into array Secondly WarehouseItem where each record is store How can I get a list of array that I load to CSVParser Class and store them to WarehouseItem and... (0 Replies)
Discussion started by: guidely
0 Replies

8. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

9. Programming

Simplify setter and getter of java class

I am trying to verify my understanding on setter and getter on java class with this example: //MaximumFinder2.java import java.util.Scanner; public class MaximumFinder2 { public static void main (String args) { Scanner input = new Scanner(System.in); ... (6 Replies)
Discussion started by: yifangt
6 Replies
GETTIMEOFDAY(2) 						System Calls Manual						   GETTIMEOFDAY(2)

NAME
gettimeofday, settimeofday - get/set date and time SYNOPSIS
#include <sys/time.h> gettimeofday(tp, tzp) struct timeval *tp; struct timezone *tzp; settimeofday(tp, tzp) struct timeval *tp; struct timezone *tzp; DESCRIPTION
The system's notion of the current Greenwich time and the current time zone is obtained with the gettimeofday call, and set with the set- timeofday call. The time is expressed in seconds and microseconds since midnight (0 hour), January 1, 1970. The resolution of the system clock is hardware dependent, and the time may be updated continuously or in ``ticks.'' If tzp is zero, the time zone information will not be returned or set. The structures pointed to by tp and tzp are defined in <sys/time.h> as: struct timeval { long tv_sec; /* seconds since Jan. 1, 1970 */ long tv_usec; /* and microseconds */ }; struct timezone { int tz_minuteswest; /* of Greenwich */ int tz_dsttime; /* type of dst correction to apply */ }; The timezone structure indicates the local time zone (measured in minutes of time westward from Greenwich), and a flag that, if nonzero, indicates that Daylight Saving time applies locally during the appropriate part of the year. Only the super-user may set the time of day or time zone. RETURN
A 0 return value indicates that the call succeeded. A -1 return value indicates an error occurred, and in this case an error code is stored into the global variable errno. ERRORS
The following error codes may be set in errno: [EFAULT] An argument address referenced invalid memory. [EPERM] A user other than the super-user attempted to set the time. SEE ALSO
date(1), adjtime(2), ctime(3), timed(8) 4th Berkeley Distribution May 14, 1986 GETTIMEOFDAY(2)
All times are GMT -4. The time now is 01:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy