• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

date format conversion to MM/dd/yyyy hh:mm a

 
Greenhorn
Posts: 20
  • Number of slices to send:
    Optional 'thank-you' note:
hi all

i have to convert date format of "2008-03-30T05:00:00.000+02:00" to
MM/dd/yyyy hh:mm a

please help me in this

thanks in advance
 
Ranch Hand
Posts: 129
  • Number of slices to send:
    Optional 'thank-you' note:
SimpleDateFormat might help you with that.
Here: SimpleDateFormat
 
sony rao
Greenhorn
Posts: 20
  • Number of slices to send:
    Optional 'thank-you' note:
checked SimpleDateFormat

"yyyy-MM-dd'T'HH:mm:ss.SSS" corresponds to "2001-9-11T18:15:00.000"

how do i go about with "+02:00" ?
 
Java Cowboy
Posts: 16084
88
  • Number of slices to send:
    Optional 'thank-you' note:
The "+02:00" is the timezone.

Unfortunately SimpleDateFormat does not have many options to format the time zone. You can use the capital letter 'Z' in the format string to specify the timezone, but this will format it as "+0200" (without the colon). So what you can do is use 'Z' and then insert the colon yourself afterwards:
 
sony rao
Greenhorn
Posts: 20
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:
i have given my code that converts date in "yyyy-MM-dd'T'HH:mm:ss.SSS" format to
"MM/dd/yyyy hh:mm a" format.

try{
String s1 = "2001-9-11T15:30:00.000";
Date d = (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS")).parse(s1);
String s2 = (new SimpleDateFormat("MM/dd/yyyy hh:mm a")).format(d);
System.out.println("s2 "+s2);
} catch(Exception e) {
e.printStackTrace();
}

but i dont know how to convert if a date is of
"2008-03-30T05:00:00.000+02:00" format


please guide me
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Number of slices to send:
    Optional 'thank-you' note:
Have you tried using the Z element like Jesper suggested?
 
sony rao
Greenhorn
Posts: 20
  • Number of slices to send:
    Optional 'thank-you' note:
hi Henrique

i tried what Jesper said..

Date now = new Date();
System.out.println("date--> " + now);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String s = df.format(now);
String result = s.substring(0, 26) + ":" + s.substring(27);
System.out.println("result--> " + result);

output:

date--> Fri Mar 14 10:27:31 IST 2008
result--> 2008-03-14T10:27:31.197+05:0

"2008-03-14T10:27:31.197+05:0" is not the format i want my result to be.
it should be in MM/dd/yyyy hh:mm a format
 
Greenhorn
Posts: 17
  • Number of slices to send:
    Optional 'thank-you' note:
Hi sony,
Try this....


Date-->Fri Mar 14 13:50:07 SGT 2008
New Date--->03/14/2008 01:50 PM
[ March 13, 2008: Message edited by: Laxman Guru ]
 
sony rao
Greenhorn
Posts: 20
  • Number of slices to send:
    Optional 'thank-you' note:
hi laxman

thanks for responding
source date format is "Fri Mar 14 13:50:07 SGT 2008" as per your code

but in my case source date is in "2008-03-14T11:53:31.470+05:00" format
which i need to format it to MM/dd/yyyy hh:mm a
[ March 14, 2008: Message edited by: sony rao ]
 
Laxman Guru
Greenhorn
Posts: 17
  • Number of slices to send:
    Optional 'thank-you' note:
Hi sony,
This is the solution as far as i now...here i hard coded the values...
Try a better solution(if it isn't helpful!!!)....

OldDate-->2008-03-14T11:53:31.200+05:00
NewDate-->03/14/2008 02:53 PM
[ March 14, 2008: Message edited by: Laxman Guru ]
 
sony rao
Greenhorn
Posts: 20
  • Number of slices to send:
    Optional 'thank-you' note:
hi laxman

thanks for your response.

as of now iam using this code

SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String s1 = "2008-03-30T15:30:00.000+02:00";
s1 = s1.substring(0, s1.indexOf('.'));
try {
System.out.println("Result==> "+sdf1.format(sdf2.parse(s1)));
} catch (Exception e) {
e.printStackTrace();
}
 
Laxman Guru
Greenhorn
Posts: 17
  • Number of slices to send:
    Optional 'thank-you' note:
For the same input(2008-03-30T15:30:00.000+02:00)
Your code yields "Result==> 03/30/2008 03:30 PM"
and mine gives "NewDate-->03/30/2008 09:30 PM"....Now i m wondering How i m going to learn java?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
  • Number of slices to send:
    Optional 'thank-you' note:

Originally posted by sony rao:
hi Henrique

i tried what Jesper said..

Date now = new Date();
System.out.println("date--> " + now);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String s = df.format(now);
String result = s.substring(0, 26) + ":" + s.substring(27);
System.out.println("result--> " + result);

output:

date--> Fri Mar 14 10:27:31 IST 2008
result--> 2008-03-14T10:27:31.197+05:0

"2008-03-14T10:27:31.197+05:0" is not the format i want my result to be.
it should be in MM/dd/yyyy hh:mm a format


So I made a little mistake. It should have been:

String result = s.substring(0, 26) + ":" + s.substring(26);

But what do you really want? First you said you wanted a format like 2008-03-14T10:27:31.197+05:00 and now you're talking about MM/dd/yyyy hh:mm.

Do you mean you want to parse a date in a format like 2008-03-14T10:27:31.197+05:00, and then format it into MM/dd/yyyy hh:mm? You can do that like this:

1. Manually remove the ":" from the input string using substring().
2. Use a SimpleDateFormat object with the format "yyyy-MM-dd'T'HH:mm:ss.SSSZ" and call parse() on it to parse the input string into a Date object.
3. Use another SimpleDateFormat object with the format "MM/dd/yyyy hh:mm" and call format() on it to format the Date object into the output string.
[ March 14, 2008: Message edited by: Jesper Young ]
 
sony rao
Greenhorn
Posts: 20
  • Number of slices to send:
    Optional 'thank-you' note:
hi Jesper

my very first statement was .....

i have to convert date format of "2008-03-30T05:00:00.000+02:00" to
MM/dd/yyyy hh:mm a

i think this clearly explains that i want to convert datetime in "2008-03-30T05:00:00.000+02:00" format to MM/dd/yyyy hh:mm a format.
[ March 14, 2008: Message edited by: sony rao ]
 
Ranch Hand
Posts: 34
  • Number of slices to send:
    Optional 'thank-you' note:
Hey,

I just need a small favor.

I have a date in "2009-12-01T00:00:00-05:00"

I need that in MM/dd/yyyy format.

Can someone help me in this.


Thanks.
Pawan
 
Ranch Hand
Posts: 312
  • Number of slices to send:
    Optional 'thank-you' note:
What's the point of this? Learning dates or getting a good solution to the issue? The answer is different :P
 
Pawan Kalyan
Ranch Hand
Posts: 34
  • Number of slices to send:
    Optional 'thank-you' note:
I would greatly appreciate if someone posts a solution for this.

And i am trying to get the return type as Date in the format MM/dd/yyyy.


Thanks again.
 
Ranch Hand
Posts: 710
  • Number of slices to send:
    Optional 'thank-you' note:

Pawan Kalyan wrote:I would greatly appreciate if someone posts a solution for this.

And i am trying to get the return type as Date in the format MM/dd/yyyy.


Thanks again.



Have you looked over this thread and written anything yet? No one here will provide you with code to do what you are asking, but we are more than willing to help you with problems/issues you encounter while writing it.
 
Pawan Kalyan
Ranch Hand
Posts: 34
  • Number of slices to send:
    Optional 'thank-you' note:

W. Joe Smith wrote

No one here will provide you with code to do what you are asking



i am having a problem with parsing the date using simpledateformatter.

Thats why i have posted and if someone could guide me then that would be really great.
I dont see a point why someone should not help me in giving the syntax or code.

I dont think you will have any problem if someone wants to give the solution.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Number of slices to send:
    Optional 'thank-you' note:

Pawan Kalyan wrote:

W. Joe Smith wrote

No one here will provide you with code to do what you are asking



i am having a problem with parsing the date using simpledateformatter.

Thats why i have posted and if someone could guide me then that would be really great.
I dont see a point why someone should not help me in giving the syntax or code.

I dont think you will have any problem if someone wants to give the solution.



If someone wants to give you some sample code I don't think anyone will have a problem with it, but NotACodeMill is a standard policy. I'm not personally objecting to someone giving you guidance using code, but providing the whole code to do what you ask would be a little much. I'm sorry if I misread your message and you are in fact asking for guidance and not a pre-written code solution.
 
Greenhorn
Posts: 1
  • Number of slices to send:
    Optional 'thank-you' note:

Hello Jesper.

I have a String which gives me date in the following format ----"2010-05-06 17:02:00.0"

i want to convert it in "06-05-2010 17:02:00.0"

Please help me in this regard..

Thanks


Jesper Young wrote:The "+02:00" is the timezone.

Unfortunately SimpleDateFormat does not have many options to format the time zone. You can use the capital letter 'Z' in the format string to specify the timezone, but this will format it as "+0200" (without the colon). So what you can do is use 'Z' and then insert the colon yourself afterwards:

 
Ranch Hand
Posts: 53
  • Number of slices to send:
    Optional 'thank-you' note:
In the same Thread you can find the answer, posted by Laxman Guru.However as per your request i have modified his code for you.



The output is :

 
Marshal
Posts: 79392
377
  • Number of slices to send:
    Optional 'thank-you' note:
Welcome to the Ranch Rahul Gurubhai
 
Ranch Hand
Posts: 88
  • Number of slices to send:
    Optional 'thank-you' note:
I have a similar problem. I get my date in the format yyyy-mm-dd hh:mm:ss.
I want to convert it into the format DDD MMM dd HH:mm:ss yyyy.
Example: Fri Jul 02 17:40:22 2010
Is there any methods by which i can set it to the desired format?
Thanks in advance.!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |