Skip to main content

Posts

Showing posts with the label date

How to auto insert Current DATE in SQL with Java / Hibernate

I need to add automatically the current date into my Database when I create a new OperantionBank. I'm using Hibernate. Thanks import java.io.Serializable; import java.sql.Date; import javax.persistence.*; import org.hibernate.annotations.Generated; import org.hibernate.annotations.GenerationTime; @Entity public class OperationBank implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String wordring; private Double amount; @Generated(GenerationTime.ALWAYS) @Temporal(javax.persistence.TemporalType.DATE) private Date dateoperation = new java.sql.Date(new java.util.Date().getTime()); @OneToOne private Account account;

unexpected output while converting a string to date in java

I have a string "12/9/2010 4:39:38 PM" which i have to convert to a date object. I am using the following code to do it: String str = "12/9/2010 4:39:38 PM"; DateFormat formatter ; Date date ; formatter = new SimpleDateFormat("M/dd/yyyy H:m:s a"); date =(Date)formatter.parse(str); System.out.println("date printed"+date); However, when im printing the output, i see Thu Dec 09 04:39:38 IST 2010 How do I get the date exactly the way I declared in the string i.e 12/9/2010 4:39:38 PM as output? Pls help

How do I determine if a string is date format?

I have some strings like this: 2012-02-05T07:42:47.000Z mixed with other strings. It is always in this format. (but the numbers are not the same, of course...the times are different) (not Sun, 05 Feb 2012 07:42:47 GMT ) I want to know whether a string matches that format. How can I determine that? It's so complicated with the colons and dots and stuff.