im new to java ..im learning myself..

i want the source code for 12hr to24hr conversion of time..
ie if i give input 1pm then my program should gives this in 24hr version as 13hr.....

i hope u pepole will help me....

Regards
kavitha

all you do is sometthing like:

IF time > 12:59 then
time = time - 12
endif

so if i input 13:00 it would give me 1
and if i input 12:00 it would still give me 12

all you do is sometthing like:

IF time > 12:59 then
time = time - 12
endif

so if i input 13:00 it would give me 1
and if i input 12:00 it would still give me 12

no way jbennet you took it wrong way, question is how to get 13:00 out of 1pm. Not oposite :cheesy:
Question is how the user enter time, in one go ass string (1pm, 4pm, etc)
or first entry is integer and second is string. So think about it what data you want to read in?

if timestring = "pm" then
time = time + 12
endif

you sujjested me to do the fallowing.......
IF time > 12:59 then
time = time - 12
endif

so if i input 13:00 it would give me 1
and if i input 12:00 it would still give me 12

but... i dont think this ll solve my question ..
my question is 12 to 24 hr conversion and not 24 to 12 hr..
moreover in your logic i dont understand..if input is 12 then out still will be 12 how this possible??????????

ok heres some vb code (dont know java so meh) for 12 to 24h

``````dim time as integer
dim timestring as string

time = inputbox "Enter The time in 12 hour"
timestring = inputbox "Is it AM or PM?"

if time > 12:59 AND timestring = "pm" then
time = time + 12
endif

msgbox("The time is: " &time " in 24h clock")``````

EDIT: Woops, sorry i hope i dontt start a flamewar by posing VB in a java forum

Woops, sorry i hope i dontt start a flamewar by posing VB in a java forum

Nah, but java is preferred here. :cheesy:

Do you know c# the syntax is similar.

i know c# but only in the context of [EMAIL="ASP.@NET"]ASP.NET[/EMAIL]
i know a little c++ but java confuses me

i know c# but only in the context of [EMAIL="ASP.@NET"]ASP.NET[/EMAIL]
i know a little c++ but java confuses me

Hmm. If you have designed your own classes in vb.net elements should be able to carry over to java. ( well the ideas anyway)

I don't what level of object orientated programming you're at though. :)

As with all languages mastery comes with practise solving problems.

yeah i know OOP in VBvery well

downloaded netbeans and am trying it now

``````Date d = new Date();
SimpleDateFormat sf12 = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
SimpleDateFormat sf24 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");

// use sf12 to parse or format a date/string to get a
Date d1a = sf12.parse("21/12/2009 01:23:12 pm");
Date d1b = sf12.parse("21/12/2009 01:23:12 am");
Date d2 = sf24.parse("21/12/2009 01:23:12");

System.out.println(d1a);
System.out.println(d1b);
System.out.println(d2);

// convert date to str
System.out.println(sf12.format(new Date()));
System.out.println(sf24.format(new Date()));

Calendar cal = Calendar.getInstance();
//Calendar cal = cal.setTime(d);
System.out.print(cal.get(Calendar.HOUR)); // for 12hr
System.out.println(" "+ (cal.get(Calendar.AM_PM)==Calendar.AM?"AM":"PM")); // for 12hr
System.out.println(cal.get(Calendar.HOUR_OF_DAY)); // 24hr``````

Sorry for posting in an old thread, but I was looking for something else and this came up, so while it might be old in your forum, it still appears in current search engine results

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.