This question already has answers here:
How to get the current date/time in Java [duplicate]
(28 answers)
Closed 9 years ago.
How to get current java date? I need to use it in my app for setting posting time. I tried use DateSelecter libdary but that didnt work in the way I needed I to, it printed it in a non human readable way.
You're missing the java tsg. But this is how to get thr date:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date));
Related
This question already has answers here:
How to get Java to show the day of month from a date?
(4 answers)
Closed 6 years ago.
I'm trying to print a day of the given date. How can I do that?
String date = "2015.05.12";
SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
Date bornDate = format.parse(date);
System.out.println(bornDate.getDay());//this prints "2" instead of "12"
You can use bornDate.getDate() to get day. You shall use calendar class as methods on date are deprecated.
This question already has answers here:
java date problem in parsing
(4 answers)
Closed 7 years ago.
I am setting the date in gui using JDateChooser , but it is not taking the proper value . I have used the format
DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
I am choosing the date from the calender provided by JDateChooser, but the month value that it is taking finally is out of bounds!!! I have no clue. There is no problem in the calender they have provided. But the value they take after processing is clearly out of bounds.
The jar used by me is : jcalender-1.4.jar
mm is minutes. You want MM. It's in the documentation.
Need to change yyyy.MM.ddon this format . may be it works
This question already has answers here:
Converting ISO 8601-compliant String to java.util.Date
(31 answers)
Closed 7 years ago.
I got a date 2014-01-01T01:14:48.000+08:00 from a web server. Does anyone know how to parse this correctly? How to get its time offset?
String s="2014-01-01T01:14:48.000+08:00";
SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
System.out.println(sdf.format(s));
You need something like this,
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSX");
System.out.println(sdf.parse(y));
The X is for timezone.
This question already has answers here:
Convert Date/Time for given Timezone - java
(16 answers)
Closed 8 years ago.
I have user input date with TimeZone "GMT +5:30". But JVM is using "GMT +0:00". I want to convert Date from "GMT +5:30" to "GMT +0:00".
Thanks
Date in Java dont have a timezone. You need to try like this:
SimpleDateFormat df = new SimpleDateFormat();
df.setTimeZone(TimeZone.getTimeZone("GMT+5.30"));
System.out.println(df.format(c.getTime()));
Also you can use the Joda-Time
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android: how to get the current day of the week (Monday, etc…) in user language?
I want to get the date of the specific day in java for android application development.
eg. For Sunday
7.8.2011
14.8.2011
21.8.2011
Date date1 = (new GregorianCalendar(2011 , Calendar.AUGUST, 28)).getTime();
Format formatter = new SimpleDateFormat("EEEE");
String s = formatter.format(date1); // s==Sunday
Take a look at the Calendar Class. You can instantiate it using the Calendar.getInstance() method.
http://download.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html
i think its something like this cal.get(Calendar.DAY_OF_WEEK)