Going from MM/DD/YYYY to DD-MMM-YYYY in java
Is there a method in Java that I can use to convert MM/DD/YYYY
to DD-MMM-YYYY
?
For example: 05/01/1999
to 01-MAY-99
Thanks!
java date-format
add a comment |
Is there a method in Java that I can use to convert MM/DD/YYYY
to DD-MMM-YYYY
?
For example: 05/01/1999
to 01-MAY-99
Thanks!
java date-format
Note that your pattern syntax is in fact invalid. It'sy
for years andd
for day of month. TheY
has no meaning andD
is day of year. You want to convert fromMM/dd/yyyy
todd-MMM-yyyy
.
– BalusC
Nov 12 '10 at 22:33
Thanks. Being new to Java, it is very helpful to have things like that pointed out to me.
– javan_novice
Nov 13 '10 at 15:52
You should have the Locale.English at the options:stackoverflow.com/a/2603676/2114308
– Phuong
Jan 29 '16 at 4:42
add a comment |
Is there a method in Java that I can use to convert MM/DD/YYYY
to DD-MMM-YYYY
?
For example: 05/01/1999
to 01-MAY-99
Thanks!
java date-format
Is there a method in Java that I can use to convert MM/DD/YYYY
to DD-MMM-YYYY
?
For example: 05/01/1999
to 01-MAY-99
Thanks!
java date-format
java date-format
edited Jun 1 '17 at 11:56
Blasanka
3,22541930
3,22541930
asked Nov 12 '10 at 22:27
javan_novice
44112
44112
Note that your pattern syntax is in fact invalid. It'sy
for years andd
for day of month. TheY
has no meaning andD
is day of year. You want to convert fromMM/dd/yyyy
todd-MMM-yyyy
.
– BalusC
Nov 12 '10 at 22:33
Thanks. Being new to Java, it is very helpful to have things like that pointed out to me.
– javan_novice
Nov 13 '10 at 15:52
You should have the Locale.English at the options:stackoverflow.com/a/2603676/2114308
– Phuong
Jan 29 '16 at 4:42
add a comment |
Note that your pattern syntax is in fact invalid. It'sy
for years andd
for day of month. TheY
has no meaning andD
is day of year. You want to convert fromMM/dd/yyyy
todd-MMM-yyyy
.
– BalusC
Nov 12 '10 at 22:33
Thanks. Being new to Java, it is very helpful to have things like that pointed out to me.
– javan_novice
Nov 13 '10 at 15:52
You should have the Locale.English at the options:stackoverflow.com/a/2603676/2114308
– Phuong
Jan 29 '16 at 4:42
Note that your pattern syntax is in fact invalid. It's
y
for years and d
for day of month. The Y
has no meaning and D
is day of year. You want to convert from MM/dd/yyyy
to dd-MMM-yyyy
.– BalusC
Nov 12 '10 at 22:33
Note that your pattern syntax is in fact invalid. It's
y
for years and d
for day of month. The Y
has no meaning and D
is day of year. You want to convert from MM/dd/yyyy
to dd-MMM-yyyy
.– BalusC
Nov 12 '10 at 22:33
Thanks. Being new to Java, it is very helpful to have things like that pointed out to me.
– javan_novice
Nov 13 '10 at 15:52
Thanks. Being new to Java, it is very helpful to have things like that pointed out to me.
– javan_novice
Nov 13 '10 at 15:52
You should have the Locale.English at the options:stackoverflow.com/a/2603676/2114308
– Phuong
Jan 29 '16 at 4:42
You should have the Locale.English at the options:stackoverflow.com/a/2603676/2114308
– Phuong
Jan 29 '16 at 4:42
add a comment |
6 Answers
6
active
oldest
votes
Use a SimpleDateFormat to parse the date and then print it out with a SimpleDateFormat withe the desired format.
Here's some code:
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
Date date = format1.parse("05/01/1999");
System.out.println(format2.format(date));
Output:
01-May-99
2
You may want to supply aLocale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.
– BalusC
Nov 12 '10 at 22:36
Very true, you can also set the time zone withformat1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
1
For readers coming later to this question: TheSimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better injava.time
, the modern Java date and time API and itsDateTimeFormatter
. See the correct answer by Md. Asaduzzaman.
– Ole V.V.
Nov 11 at 10:06
add a comment |
java.time
You should use java.time classes with Java 8 and later. To use java.time, add:
import java.time.* ;
Below is an example, how you can format date.
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String date = "15-Oct-2018";
LocalDate localDate = LocalDate.parse(date, formatter);
System.out.println(localDate);
System.out.println(formatter.format(localDate));
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
I suggest always specifying explicitly the intendedLocale
needed for translating the name of the month. Here we would use something English related, such asLocale.CANADA
orLocale.US
orLocale.UK
. Pass as the optional second argument toofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.
– Basil Bourque
Nov 12 at 20:17
2
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terribleDate
/Calendar
/SimpleDateFormat
classes.
– Basil Bourque
Nov 12 at 20:22
add a comment |
Try this,
Date currDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String strCurrDate = dateFormat.format(currDate);
System.out.println("strCurrDate->"+strCurrDate);
FYI, the terribly troublesome old date-time classes such asjava.util.Date
,java.util.Calendar
, andjava.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.
– Basil Bourque
Nov 12 at 20:22
add a comment |
Try this
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // Set your date format
String currentData = sdf.format(new Date());
Toast.makeText(getApplicationContext(), ""+currentData,Toast.LENGTH_SHORT ).show();
add a comment |
Below should work.
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
Date oldDate = df.parse(df.format(date)); //this date is your old date object
add a comment |
formatter = new SimpleDateFormat("dd-MMM-yy");
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4169634%2fgoing-from-mm-dd-yyyy-to-dd-mmm-yyyy-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use a SimpleDateFormat to parse the date and then print it out with a SimpleDateFormat withe the desired format.
Here's some code:
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
Date date = format1.parse("05/01/1999");
System.out.println(format2.format(date));
Output:
01-May-99
2
You may want to supply aLocale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.
– BalusC
Nov 12 '10 at 22:36
Very true, you can also set the time zone withformat1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
1
For readers coming later to this question: TheSimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better injava.time
, the modern Java date and time API and itsDateTimeFormatter
. See the correct answer by Md. Asaduzzaman.
– Ole V.V.
Nov 11 at 10:06
add a comment |
Use a SimpleDateFormat to parse the date and then print it out with a SimpleDateFormat withe the desired format.
Here's some code:
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
Date date = format1.parse("05/01/1999");
System.out.println(format2.format(date));
Output:
01-May-99
2
You may want to supply aLocale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.
– BalusC
Nov 12 '10 at 22:36
Very true, you can also set the time zone withformat1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
1
For readers coming later to this question: TheSimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better injava.time
, the modern Java date and time API and itsDateTimeFormatter
. See the correct answer by Md. Asaduzzaman.
– Ole V.V.
Nov 11 at 10:06
add a comment |
Use a SimpleDateFormat to parse the date and then print it out with a SimpleDateFormat withe the desired format.
Here's some code:
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
Date date = format1.parse("05/01/1999");
System.out.println(format2.format(date));
Output:
01-May-99
Use a SimpleDateFormat to parse the date and then print it out with a SimpleDateFormat withe the desired format.
Here's some code:
SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy");
Date date = format1.parse("05/01/1999");
System.out.println(format2.format(date));
Output:
01-May-99
answered Nov 12 '10 at 22:30
Brian Clements
3,1211824
3,1211824
2
You may want to supply aLocale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.
– BalusC
Nov 12 '10 at 22:36
Very true, you can also set the time zone withformat1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
1
For readers coming later to this question: TheSimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better injava.time
, the modern Java date and time API and itsDateTimeFormatter
. See the correct answer by Md. Asaduzzaman.
– Ole V.V.
Nov 11 at 10:06
add a comment |
2
You may want to supply aLocale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.
– BalusC
Nov 12 '10 at 22:36
Very true, you can also set the time zone withformat1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
1
For readers coming later to this question: TheSimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better injava.time
, the modern Java date and time API and itsDateTimeFormatter
. See the correct answer by Md. Asaduzzaman.
– Ole V.V.
Nov 11 at 10:06
2
2
You may want to supply a
Locale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.– BalusC
Nov 12 '10 at 22:36
You may want to supply a
Locale
to the SDF constructor, else it will just take the platform default locale for month names, which may not be the one you want to use.– BalusC
Nov 12 '10 at 22:36
Very true, you can also set the time zone with
format1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
Very true, you can also set the time zone with
format1.setTimeZone(TimeZone.getTimeZone("GMT"));
– Brian Clements
Nov 12 '10 at 22:38
1
1
For readers coming later to this question: The
SimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better in java.time
, the modern Java date and time API and its DateTimeFormatter
. See the correct answer by Md. Asaduzzaman.– Ole V.V.
Nov 11 at 10:06
For readers coming later to this question: The
SimpleDateFormat
class is long outdated and notoriously troublesome. Don’t use it. Since 2014 we have so much better in java.time
, the modern Java date and time API and its DateTimeFormatter
. See the correct answer by Md. Asaduzzaman.– Ole V.V.
Nov 11 at 10:06
add a comment |
java.time
You should use java.time classes with Java 8 and later. To use java.time, add:
import java.time.* ;
Below is an example, how you can format date.
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String date = "15-Oct-2018";
LocalDate localDate = LocalDate.parse(date, formatter);
System.out.println(localDate);
System.out.println(formatter.format(localDate));
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
I suggest always specifying explicitly the intendedLocale
needed for translating the name of the month. Here we would use something English related, such asLocale.CANADA
orLocale.US
orLocale.UK
. Pass as the optional second argument toofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.
– Basil Bourque
Nov 12 at 20:17
2
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terribleDate
/Calendar
/SimpleDateFormat
classes.
– Basil Bourque
Nov 12 at 20:22
add a comment |
java.time
You should use java.time classes with Java 8 and later. To use java.time, add:
import java.time.* ;
Below is an example, how you can format date.
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String date = "15-Oct-2018";
LocalDate localDate = LocalDate.parse(date, formatter);
System.out.println(localDate);
System.out.println(formatter.format(localDate));
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
I suggest always specifying explicitly the intendedLocale
needed for translating the name of the month. Here we would use something English related, such asLocale.CANADA
orLocale.US
orLocale.UK
. Pass as the optional second argument toofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.
– Basil Bourque
Nov 12 at 20:17
2
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terribleDate
/Calendar
/SimpleDateFormat
classes.
– Basil Bourque
Nov 12 at 20:22
add a comment |
java.time
You should use java.time classes with Java 8 and later. To use java.time, add:
import java.time.* ;
Below is an example, how you can format date.
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String date = "15-Oct-2018";
LocalDate localDate = LocalDate.parse(date, formatter);
System.out.println(localDate);
System.out.println(formatter.format(localDate));
java.time
You should use java.time classes with Java 8 and later. To use java.time, add:
import java.time.* ;
Below is an example, how you can format date.
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String date = "15-Oct-2018";
LocalDate localDate = LocalDate.parse(date, formatter);
System.out.println(localDate);
System.out.println(formatter.format(localDate));
edited Nov 12 at 20:18
Basil Bourque
105k25359523
105k25359523
answered Nov 11 at 7:24
Md. Asaduzzaman
473
473
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
I suggest always specifying explicitly the intendedLocale
needed for translating the name of the month. Here we would use something English related, such asLocale.CANADA
orLocale.US
orLocale.UK
. Pass as the optional second argument toofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.
– Basil Bourque
Nov 12 at 20:17
2
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terribleDate
/Calendar
/SimpleDateFormat
classes.
– Basil Bourque
Nov 12 at 20:22
add a comment |
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
I suggest always specifying explicitly the intendedLocale
needed for translating the name of the month. Here we would use something English related, such asLocale.CANADA
orLocale.US
orLocale.UK
. Pass as the optional second argument toofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.
– Basil Bourque
Nov 12 at 20:17
2
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terribleDate
/Calendar
/SimpleDateFormat
classes.
– Basil Bourque
Nov 12 at 20:22
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
@Billal, If you add import java.time.*; in code block. then you should also add class name definition. I just want to clarify the developers which package I am using
– Md. Asaduzzaman
Nov 11 at 8:35
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
Yes, that is very right, I actually forgot to roll back my edit, sorry, thank you
– Billal Begueradj
Nov 11 at 8:37
I suggest always specifying explicitly the intended
Locale
needed for translating the name of the month. Here we would use something English related, such as Locale.CANADA
or Locale.US
or Locale.UK
. Pass as the optional second argument to ofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.– Basil Bourque
Nov 12 at 20:17
I suggest always specifying explicitly the intended
Locale
needed for translating the name of the month. Here we would use something English related, such as Locale.CANADA
or Locale.US
or Locale.UK
. Pass as the optional second argument to ofPattern
method. The current default locale at runtime might not be English, in which case this code with this input would fail, throwing an exception.– Basil Bourque
Nov 12 at 20:17
2
2
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terrible
Date
/Calendar
/SimpleDateFormat
classes.– Basil Bourque
Nov 12 at 20:22
For Java 6 & 7, must of the java.time functionality is available in the ThreeTen-Backport project. So no need to ever use the terrible
Date
/Calendar
/SimpleDateFormat
classes.– Basil Bourque
Nov 12 at 20:22
add a comment |
Try this,
Date currDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String strCurrDate = dateFormat.format(currDate);
System.out.println("strCurrDate->"+strCurrDate);
FYI, the terribly troublesome old date-time classes such asjava.util.Date
,java.util.Calendar
, andjava.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.
– Basil Bourque
Nov 12 at 20:22
add a comment |
Try this,
Date currDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String strCurrDate = dateFormat.format(currDate);
System.out.println("strCurrDate->"+strCurrDate);
FYI, the terribly troublesome old date-time classes such asjava.util.Date
,java.util.Calendar
, andjava.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.
– Basil Bourque
Nov 12 at 20:22
add a comment |
Try this,
Date currDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String strCurrDate = dateFormat.format(currDate);
System.out.println("strCurrDate->"+strCurrDate);
Try this,
Date currDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
String strCurrDate = dateFormat.format(currDate);
System.out.println("strCurrDate->"+strCurrDate);
answered Feb 11 '13 at 5:39
ASIK RAJA A
17519
17519
FYI, the terribly troublesome old date-time classes such asjava.util.Date
,java.util.Calendar
, andjava.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.
– Basil Bourque
Nov 12 at 20:22
add a comment |
FYI, the terribly troublesome old date-time classes such asjava.util.Date
,java.util.Calendar
, andjava.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.
– Basil Bourque
Nov 12 at 20:22
FYI, the terribly troublesome old date-time classes such as
java.util.Date
, java.util.Calendar
, and java.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.– Basil Bourque
Nov 12 at 20:22
FYI, the terribly troublesome old date-time classes such as
java.util.Date
, java.util.Calendar
, and java.text.SimpleDateFormat
are now legacy, supplanted by the java.time classes built into Java 8 and later. See Tutorial by Oracle.– Basil Bourque
Nov 12 at 20:22
add a comment |
Try this
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // Set your date format
String currentData = sdf.format(new Date());
Toast.makeText(getApplicationContext(), ""+currentData,Toast.LENGTH_SHORT ).show();
add a comment |
Try this
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // Set your date format
String currentData = sdf.format(new Date());
Toast.makeText(getApplicationContext(), ""+currentData,Toast.LENGTH_SHORT ).show();
add a comment |
Try this
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // Set your date format
String currentData = sdf.format(new Date());
Toast.makeText(getApplicationContext(), ""+currentData,Toast.LENGTH_SHORT ).show();
Try this
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // Set your date format
String currentData = sdf.format(new Date());
Toast.makeText(getApplicationContext(), ""+currentData,Toast.LENGTH_SHORT ).show();
answered Jul 23 '15 at 7:05
Jatin Devani
120214
120214
add a comment |
add a comment |
Below should work.
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
Date oldDate = df.parse(df.format(date)); //this date is your old date object
add a comment |
Below should work.
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
Date oldDate = df.parse(df.format(date)); //this date is your old date object
add a comment |
Below should work.
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
Date oldDate = df.parse(df.format(date)); //this date is your old date object
Below should work.
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
Date oldDate = df.parse(df.format(date)); //this date is your old date object
answered Nov 12 '10 at 22:37
CoolBeans
18.1k107094
18.1k107094
add a comment |
add a comment |
formatter = new SimpleDateFormat("dd-MMM-yy");
add a comment |
formatter = new SimpleDateFormat("dd-MMM-yy");
add a comment |
formatter = new SimpleDateFormat("dd-MMM-yy");
formatter = new SimpleDateFormat("dd-MMM-yy");
edited Jul 18 '13 at 23:30
Biclops
1,6191738
1,6191738
answered Nov 12 '10 at 22:33
zod
7,353215698
7,353215698
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4169634%2fgoing-from-mm-dd-yyyy-to-dd-mmm-yyyy-in-java%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Note that your pattern syntax is in fact invalid. It's
y
for years andd
for day of month. TheY
has no meaning andD
is day of year. You want to convert fromMM/dd/yyyy
todd-MMM-yyyy
.– BalusC
Nov 12 '10 at 22:33
Thanks. Being new to Java, it is very helpful to have things like that pointed out to me.
– javan_novice
Nov 13 '10 at 15:52
You should have the Locale.English at the options:stackoverflow.com/a/2603676/2114308
– Phuong
Jan 29 '16 at 4:42