Skip to content
Advertisement

Tag: date

Removing time from a Date object?

I want to remove time from Date object. But when I’m converting this date (which is in String format) it is appending time also. I don’t want time at all. What I want is simply “21/03/2012”. Answer The quick answer is : No, you are not allowed to do that. Because that is what Date use for. From javadoc of

How to convert year month day to proper UTC milliseconds from the epoch?

I am trying to convert a date into milliseconds with the following code: I get left=-2206310400000, but when I check here, I should get -2208988800000. What am I doing wrong? Answer You’re using 1 for the month number, which means February. You mean From the docs: month – the value used to set the MONTH calendar field. Month value is

Unparseable date exception in java

These lines of codes causees this exception what is the possible solution ? Answer Your format is completely wrong. Not only are you using mm (which means minutes) when you probably meant MM, but this: is clearly not in the format You probably want something like EDIT: That works for me in desktop Java: You may want to set the

java SimpleDateFormat

in Java, how to parse a date string that contains a letter that does not represent a pattern? “2007-11-02T14:46:03+01:00″ String date =”2007-11-02T14:46:03+01:00”; String format = “yyyy-MM-ddTHH:mm:ssz”; new SimpleDateFormat(format).parse(date); Exception in thread “main” java.lang.IllegalArgumentException: Illegal pattern character ‘T’ at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:769) at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:576) at java.text.SimpleDateFormat.(SimpleDateFormat.java:501) at java.text.SimpleDateFormat.(SimpleDateFormat.java:476) Answer The time you’re trying to parse appears to be in ISO 8601 format. SimpleDateFormat

How to set an expiration date in java

I am trying to write some code to correctly set an expiration date given a certain date. For instance this is what i have. However, say if i the sign up date is on 5/7/2011 the expiration date output i get is on 11/6/2011 which is not exactly half of a year from the given date. Is there an easier

Checking if a date exists or not in Java

Is there any predefined class in Java such that, if I pass it a date it should return if it is a valid date or not? For example if I pass it 31st of February of some year, then it should return false, and if the date exists then it should return me true, for any date of any year.

Advertisement