Java Date String to date same format [closed] - java

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));

Related

SimpleDateFormat not working on 1629777600000 [closed]

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.

How to get all the dates of every month in Java from LocalDate in a List [closed]

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 4 years ago.
Improve this question
I want to get all the dates of a month in a list so i can show all the dates from that month on a JSF page. When the month changes the amount of dates has to change accordingly.
I Use Java 8 LocalDate.
How can i best do that?
I'm not sure how can one need to put all the dates of the month in a database, but here's a way to get the List of all the dates of the current month:
LocalDate date = LocalDate.now().withDayOfMonth(1);
LocalDate end = date.plusMonths(1);
List<LocalDate> dates = new ArrayList<>();
while(date.isBefore(end)) {
dates.add(date);
date = date.plusDays(1);
}

How to compare present date to the date which is one year old [closed]

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 6 years ago.
Improve this question
I am working on a java application where i need to compare present date to the date which is before one year or old. the old date will be coming from input file and it could be any date which is before one year. Please help me out
long millis=System.currentTimeMillis();
java.sql.Date date=new java.sql.Date(millis);
String d1 = ord.getOrderDate();
i am unable to proceed from hereenter code here
Date class has before, after and compareTo methods. See the Javadoc API. That should give you all you need.
java.util.Date API

String to date Conversion in Java [closed]

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");

Format for date object with am/pm [closed]

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()));

Categories