Sponsored Content
Full Discussion: Java Date Class
Top Forums Programming Java Date Class Post 302924424 by junior-helper on Sunday 9th of November 2014 02:38:12 PM
Old 11-09-2014
Java

Integer.parseInt has a funny side effect though. It will convert 000 to 0, 03 to 3 and so on.
Code:
import java.util.Date; // mandatory only for the "current date and time" part

public class prob4
 {
    public static void main(String args[])
    {

    String ArgumentFromCommandLine = "";
    int time = 0;

    // exit program if the supplied argument is not an integer OR
    // if no or too many arguments were supplied
    if (args.length == 1) {
        try {
        ArgumentFromCommandLine = args[0];
            time = Integer.parseInt(ArgumentFromCommandLine);
        } catch (NumberFormatException e) {
            System.err.println("Argument " + args[0] + " must be an integer.");
            System.exit(1);
        }
    }
    else {
        System.err.println("No or too many arguments were supplied.");
            System.exit(1);
    }

    // collect all values
    Long utms = System.currentTimeMillis(); // UNIX time in milliseconds
    Long uts = utms / 1000; // UNIX time in seconds
    Long utd = uts / 86400; // UNIX time in days
    Date dateandtime = new Date(); // Current date and time, default format

    // print requested value
        switch ( time )
    {
        case 0:
            System.out.println("Milliseconds since 1970: " + utms);
            break;
        case 1:
            System.out.println("Seconds since 1970: " + uts);
            break;
        case 2:
            System.out.println("Days since 1970: " + utd);
            break;
        case 3:
            System.out.println("Current date and time: " + dateandtime);
            break;
        default:
            System.out.println("Invalid");
    }

    }

}

This User Gave Thanks to junior-helper For This Post:
 

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 or set date and time

Syntax
       #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  call returns the system's notion of the current Greenwich time and the current time zone.  Time returned is expressed relative
       in seconds and microseconds since midnight January 1, 1970.

       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 superuser can set the time of day.

Return Values
       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.

Diagnostics
       The call fails under the following conditions:

       [EFAULT]       An argument address referenced invalid memory.

       [EPERM]	      A user other than the superuser attempted to set the time.

See Also
       date(1), stime(2), ctime(3)

																   gettimeofday(2)
All times are GMT -4. The time now is 06:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy