Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How to parse this String to timestamp timezone issue ?
String timestamp = "29-JAN-2014 01:00:00.000 PM EUROPE/PARIS";
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss.SSS aa ZZZ");
Date dateFormatted = null;
try {
dateFormatted = df.parse(timestamp);
} catch (ParseException execption) {
execption.printStackTrace();
}
This seems to work:
TimeZone tz = TimeZone.getTimeZone("Europe/Paris")
String timestamp = "29-JAN-2014 01:00:00.000 PM";
DateFormat df = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss.SSS aa");
df.setTimeZone(tz)
try {
dateFormatted = df.parse(timestamp);
} catch (ParseException execption) {
execption.printStackTrace();
}
But you have to split the timezone from the timestamp
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want date without time in java
unix format is
YYYYMMDDHHMMSS.miliseconds
unix string 20170817134131.384
string val = "20170817134131.384";
if (val != null) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
try {
date = df.parse(String.valueOf(val));
} catch (ParseException e) {
throw new RuntimeException("Failed to parse date: ", e);
}
return date;
}
Here's a simple solution to convert unix time to localDate and then you're free to format it as you please:
long time = 1491231860;
final LocalDate localDate = LocalDate.fromMillisSinceEpoch(unixSeconds);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
How do I parse this String in Java as date
"2017-06-12T14:45:00+05:30"
I've tried using SimpleDateFormat but it is throwing exception.
Thanks
It seems to be a valid ISO offset date time format, so this should work without requiring a formatter:
OffsetDateTime date = OffsetDateTime.parse(input);
If you really need a java.util.Date, you can then use:
Date legacyDate = Date.from(date.toInstant());
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ENGLISH);
Date date = format.parse(string);
date is your solution
Just provide correct pattern in SimpleDateForamt
String startDateString = "09/23/2009";
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date startDate;
try {
startDate = df.parse(startDateString);
String newDateString = df.format(startDate);
System.out.println(newDateString);
} catch (ParseException e) {
e.printStackTrace();
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Please help me convert time from 12 hours to 24 hours format return time should be in UTC in JAVA
This will help you to convert time to 24 Hour
public static String convertTo24Hour(String Time) {
DateFormat f1 = new SimpleDateFormat("hh:mm a"); //11:00 pm
Date d = null;
try {
d = f1.parse(Time);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DateFormat f2 = new SimpleDateFormat("HH:mm");
String x = f2.format(d); // "23:00"
return x;
}
Later on you may convert to UTC as per your wish or you may compile code in one function
public static String CalculateUTC_Time(String Date, String Time) {
String X[] = Time.split(":");
int Hours = Integer.parseInt(X[0]);
int Minutes = Integer.parseInt(X[1]);
LocalDate date = new LocalDate(Date);
LocalTime time = new LocalTime(Hours, Minutes);
DateTime dt = date.toDateTime(time);
SimpleDateFormat f2 = new SimpleDateFormat("HH:mm");
f2.setTimeZone(TimeZone.getTimeZone("UTC"));
return (f2.format(dt.toDate()));
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a Date 2014-10-01 00:00:00.0
I have to convert into 10/01.2014
How can i?
how about this one
try
{
String currentDate = "2014-10-01 00:00:00.0";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date tempDate=simpleDateFormat.parse(currentDate);
SimpleDateFormat outputDateFormat = new SimpleDateFormat("dd/MM.YYYY");
System.out.println("Output date is = "+outputDateFormat.format(tempDate));
} catch (ParseException ex)
{
System.out.println("Parse Exception");
}
Use SimpleDateFormat:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format("Your date");
try This
// Create an instance of SimpleDateFormat used for formatting
// the string representation of date (month/day/year)
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
// Get the date today using Calendar object.
Date today = Calendar.getInstance().getTime();
// Using DateFormat format method we can create a string
// representation of a date with the defined format.
String reportDate = df.format(today);
// Print what date is today!
System.out.println("Report Date: " + reportDate);
It's pretty easy if you use the JodaTime library.
DateTime dt = new DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd.YYYY");
String str = fmt.print(dt);
try this:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date d = sdf.parse("dd/MM.YYYY");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a String stating the date as "2012-12-31" how can I convert it into date format using java and store it MySQL database where the type in MySQL is of date type.
You can do as follows
String string = "2012-12-31";
DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
java.util.Date date = formatter.parse(string);
java.sql.Date sqlDate = new java.sql.Date(date.getTime()); // convert java.util.date to java.sql.date
Have a look at SimpleDateFormat
String string = "2012-12-31"; //You have like this now
DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
Date date = formatter.parse(string);
System.out.println(date);