Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java util date - Time Zone throwing illegal argument exception
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


diwakar raja
java util date - Time Zone throwing illegal argument exception
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


Sample Code

String timestamp1 = "Wed Mar 02 00:00:54 PST 2011";
Date d = new Date(timestamp1);
System.out.println(d.toString());

String timestamp2 = "Wed Mar 02 12:57:52 IST 2011";
Date d2 = new Date(timestamp2);
System.out.println(d2.toString());

The date object is not getting created for IST time zone. Java is throwing an Illegal Argument Exception Why is the second SOP always throwing an exception ? This piece of code is running on app servers on machines in different time zones ? How do I always make sure that the date gets created in a particular time zone ?


Advertisement
View Answers

March 2, 2011 at 5:29 PM


The toString() method already displaying IST by default.

Modified your code:

import java.util.*;
class Example 
{
    public static void main(String[] args) 
    {
        String timestamp1 = "Wed Mar 02 00:00:54 2011";
Date d = new Date(timestamp1);
System.out.println(d.toString());

String timestamp2 = "Wed Mar 02 12:57:52 2011";
Date d2 = new Date(timestamp2);
System.out.println(d2.toString());
    }
}


Related Tutorials/Questions & Answers:
Throwing an Exception
Throwing an Exception      ... statement to throw an exception.  The throw statement requires a single argument...; <title>Throwing an Exception in jsp</title> </head>
Example to show Argument Exception in java
Example to show Argument Exception in java  ... from Argument exception in java .Exceptions are the condition  in Java... describes  how to handle Argument exceptions appropriately in your programs
Advertisements
util packages in java
util packages in java  write a java program to display present date and after 25days what will be the date?   import java.util.*; import...){ Date today = new Date(); SimpleDateFormat sdf=new SimpleDateFormat("dd-MM
A Java program to simulate throwing a die
A Java program to simulate throwing a die  A Java program to simulate throwing a die (singular of dice) 6000 times and store the frequency with which each face of the die is uppermost after each throw in an array. A couple
Class Cast & illegal state Exception in blackberry
Class Cast & illegal state Exception in blackberry  tell me please i m facing class cast exception. when i click on Maps & iGoogle in Google Homepage on my emulator then it gives class cast & Illegal State exception
Java argument passing
Java argument passing  How many ways can an argument be passed to a subroutine and explain them
illegal start of expression - Java Beginners
illegal start of expression  here i attach my program.. which shows...); getContentPane.add(label); getContentPane.add(text); } catch (Exception e... (Exception e){} } public static void main(String[] args){ Image im=new Image
Throwing an Exception in JSTL
Throwing an Exception in JSTL     ... this example you can better understand how the exception can be thrown in JSTL.  ...;html> <head> <title>Throwing an Exception</title> <
What is command line argument in Java
What is command line argument in Java  What is command line argument in Java and how one can use it to create a program in Java? Can you post any example of command line argument program in Java?? It will be really helpful
Java Generic program with command line argument
Java Generic program with command line argument  Implement Generic to perform arithmetic evaluation using command line argument by using Java
Java Throw Built-in Exception
Java Throw Built-in Exception In this section we are discussing about throwing of built-in exceptions in Java. In Java throw and throws keywords are used... will demonstrate you about how to use throw keyword in Java to throw the exception
Getting Previous, Current and Next Day Date
previous, current and next date in java. The java util package provides... Getting Previous, Current and Next Day Date   ... the previous, current and next date to Date() constructor of java.util package
Java programme - Date Calendar
Java programme  Can you provide me the coding for Date class provided by java util package
util
util  Write a programe such as whenever any user enter the name of a country it displays the current date and time and ist also
Exception Handlerin java..
Exception Handlerin java..  can a catch block accept multiple argument and return type?? please tell with explaination
Exception Java
Exception Java  Hi, What are the Exception Java? Thanks   Hi, Read it at Java Exception. Thanks
Java Exception
Java Exception  Which is superclass of Exception
Java exception
Java exception  Can an exception be rethrown
Java exception
Java exception  What happens if an exception is not caught
why it is throwing classCastException.
why it is throwing classCastException.   public class Redwood extends Tree { public static void main(String[] args) { new Redwood().go(); } void go() { go2(new Tree(), new Redwood()); go2((Redwood) new
java exception
java exception   define an exception called no match exception tat z... { public static void main(String[] args) throws Exception { String z="Hello"; if(!z.equals("India")){ throw new Exception
Java exception
Java exception  What is the difference between exception and error
Java exception
Java exception  What is the difference between Checked and Unchecked exception
Exception - Java Interview Questions
Java Exception  My java program is throwing an Exception ..can anyone tell me how to track those exceptions?  An error will occur showing the message 'try' without 'catch' or 'finally'because jvm will search for catch
Java Exception
Java Exception  What are monitors
Java Exception
Java Exception  Why Errors are Not Checked
Java Exception
Java Exception  Why Runtime Exceptions are Not Checked
Java Exception
Java Exception  What is ?Resource leak
Java Exception
Java Exception  What is the purpose of finalization
Java exception
Java exception  Can try statements be nested
Advertisements
 

 

 

DMCA.com