converting java date to oracle date format [duplicate] - java

This question already has answers here:
Java: creating a date object from a string and inserting into MySQL
(3 answers)
Closed 9 years ago.
i am having string as 10-07-1992. i have to convert this to oracle date format like 10-jul-1992.
i tried using this
String date = fqu.getDob();
Date d = new SimpleDateFormat("dd/MM/yyyy").parse(date);
java.sql.Date sqlDate = new java.sql.Date(d.getTime());
System.out.println("sql date"+sqlDate);
this prints like 1992-07-10. but this is not recognized while inserting this value in oracle.
i dont need to_cast method. this works only in sql command prompt. i want to do this conversion inside java file.

Use Date format as dd-MMM-yyyy
Date d = new SimpleDateFormat("dd-MMM-yyyy").parse(date);
Shows output as
10-jul-1992

Can you try
Date d = new SimpleDateFormat("dd/MMM/yyyy").parse(date);

Related

Java Date Format from yyyy-MM-dd'T'HH:mm:ss.SSS+ZZZZ [duplicate]

This question already has answers here:
Cannot parse String in ISO 8601 format, lacking colon in offset, to Java 8 Date
(3 answers)
Convert date into AEST using java
(2 answers)
Java string to date conversion
(17 answers)
Closed 3 years ago.
Formatting the date somehow is giving me an exception.
The date string that I want to convert to a Date object => 2019-12-12T15:31:31.000+0000
Code for converting which gives the error Text '2019-12-12T15:31:31.000+0000' could not be parsed at index 24
Date date;
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'+'Z");
ZonedDateTime formatDateTime = ZonedDateTime.parse(dateString,formatter);
date = Date.from(formatDateTime.toInstant());
return date.toString();
}catch (Exception ex){
return ex.getLocalizedMessage();
}
I'm not sure why this isn't working, the Date has been a huge problem for me in Java. In C# there's hardly any work that needs to be done but I couldn't figure out how to parse a date string in Java.
Help is appreciated, thanks people.

Date format dd/mm/yy [duplicate]

This question already has answers here:
Convert dateTime to date in dd/MM/yy format in java
(4 answers)
Closed 3 years ago.
I got this problem in my code. I want to show a date in dd/mm/yy, for example 04/11/19.I don't know how to do it, I tried something like this:
new SimpleDateFormat("dd/mm/yy").format(getDate())
But it does mm/dd/yyyy. This is my code I tried to format:
for (Information t : list) {
tblInfo.addItem(
new Object[] { t.getName(), t.getLocation(), t.getTypeProduct().getDescription(), new SimpleDateFormat("dd/mm/yy").format(t.getTodayDate) }, null
);
}
Try this
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(getDate);

How to convert sql date to java [duplicate]

This question already has answers here:
Using setDate in PreparedStatement
(6 answers)
Closed 6 years ago.
SO i have a table in my database, date declared as date. and now i'm coding in java and i need the DATE to be inputted by the user and store it in my database. how does it work? i mean to convert date in to what? thank you!!
for now this is my code
java.util.Date utilDate = new java.util.Date();
java.sql.Date sqldate = new java.sql.Date(utilDate.getTime());
System.out.print("更新日: ");
String 更新日 = input.nextLine();
If you are using SQL SERVER, the following code will convert your date to SQL Server format.
java.util.Date utilDate = new java.util.Date(); //date that needs conversion
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); //converts to SQL date format

Java - Formatting and get name of day: Date object [duplicate]

This question already has answers here:
Change date format in a Java string
(22 answers)
Closed 7 years ago.
All
When I define a date object it automatically assumes it's MM/dd/YYYY, however I enter it as dd/MM/yyyy.
Date d1 = new Date("5/12/2015 10:30:00");
When I get the name of the day from that date it gives me the name of May 12 (Tuesday) instead of the name of december 5 (Saturday).
dateName = new SimpleDateFormat("EEEE", Locale.ENGLISH).format(d1);
Can anyone help me out?
You can use a SimpleDateFormat formatter for that.
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = format.parse("05/12/2015");
With that you can define your own format-strings!

in java, how to convert String to Date object "yyyy-MM-dd'T'HH:mm" [duplicate]

This question already has answers here:
Change date format in a Java string
(22 answers)
Closed 7 years ago.
i want to convert String "yyyy-MM-dd'T'HH:mm" (for ex,2015-04-13T10:00:00) into date object with the same format(yyyy-MM-dd'T'HH:mm). Please let me know how to do this.
String dateString = "2015-04-13T10:00:00";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
Date date = simpleDateFormat.parse(dateString);
Now if you want to display the date in the same format, you can do the following
System.out.println(simpleDateFormat.format(date)); // Outputs "2015-04-13T10:00"

Categories

Resources