Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this code
SimpleDateFormat ft = new SimpleDateFormat ("dd/MM/yyyy");
String sDate="2013-11-13";
String formattedDate=ft.format( ft.parse(sDate));
but this not working. Any help
You need to change the date format like this
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
Edit
comment question : but I need dd/mm/yyyy format?
Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2013-11-13");
String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(date);
System.out.println(formattedDate);
Change SimpleDate Format to below, and it shall work
SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");
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 1 year ago.
Improve this question
Date format coming from the database: 1629777600000
SimpleDateFormat simpleDateFormatter = new SimpleDateFormat("MM/dd/yyyy");
simpleDateFormat.format(1629777600000);
When using this simple date format I am not able to convert 1629777600000 to a viewable date
SimpleDateFormat simpleDateFormatter = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(simpleDateFormatter.format(1629777600000L));
Print: 08/24/2021
But your code does not compile:
you initialize simpleDateFormatter but use simpleDateFormat (without ter)
1629777600000 is a Long, therefore it needs an L at its end
I think the L problem is just from modifiying the code for the stackoverflow question. But the variable name is maybe a real problem in your code.
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 6 years ago.
Improve this question
I need to use Calendar class. This is my code, but it has an error certainly. How can I fix it?
String stringdate = "20161129";
String pattern = "yyyyMMdd";
Date date = new SimpleDateFormat(pattern).parse(stringdate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
Your code looks good...
2 things can happen her:
you are not using the correct DAte class (import java.util.Date;)
you are not considering (catching or rethrowing ) the ParseException
in both cases you will get a compilation error...
like type mismatch
or unhandled exception
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
2013-06-24 15:43:00.0 this is Sting
i want parse that to Date
but in same formate
if Month is Month Jan it should be 1 etc
Use the SimpleDateFormat like this:
String dateString = "2013.06.24 15:43:00";
SimpleDateFormat sdfToDate = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
Date date1 = sdfToDate.parse(dateString);
System.out.println(sdfToDate.format(date1));
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was wondering how I can just set a time such as 10:30am to a Date object from java.util.date? How would I format this? For example Date date1 = 10:30am.
try with the Calendar class then output using SimpleDateFormat
SimpleDateFormat format = new SimpleDateFormat("HH:mma");
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10);
calendar.set(Calendar.MINUTE, 30);
System.out.println(format.format(calendar.getTime()));
can't do that.Only format to String representations.
SimpleDateFormat simDateFormate = new SimpleDateFormat("hh:mm a");
System.out.println(simDateFormate.format(new Date()));
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have two date objects.
Date d1;
Date d2;
My program stores in d1, the date in the format 'dd/MM/yyyy' and in d2 in the format 'HH:mm'.
I would now like to combine these information and create a new Date object with the format 'dd/MM/yyyy HH:mm'.
Any pointers on how can I achieve so?
-V
If you are indeed using Date objects, just set the time of d1 to match that of d2.
d1.setHours(d2.getHours());
d1.setMinutes(d2.getMinutes());
Or make a new Date object if you don't want to use d1. Just parse it afterwards with SimpleDateFormat.
Note however that this is deprecated and it's better to use Calendar for this.
First, most of functionality of Date is deprecated. Use Calendar instead. Second, to parse and create string representation of date use SimpleDateFormat.
I hope these tips are enough to start. There are a lot of references in net and javadoc to continue. Good luck.
You cannot use Date for this purpose. You should instead use Calendar (from JDK) or joda-time.
try out this..
String dateValue= new java.util.Date().toString();
String concat like this..
String newDateTime = d1+""+d2+":00";
Try this
DateFormat df1=new SimpleDateFormat("dd/MM/yyyy");
DateFormat df2=new SimpleDateFormat("HH:mm");
Date d1=df1.parse("09/07/2013");
Date d2=df2.parse("14:43");
String d=df1.format(d1).toString()+" "+df2.format(d2).toString();
DateFormat newDate=new SimpleDateFormat("dd/MM/yyyy HH:mm");
System.out.println(newDate.format(newDate.parse(d)));