473,379 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

help to show integer value in a time format - newbie

dear all

i am n a situation to display from a int value into Time format,
is there any possiblity of using existing java util classes? or i need to rite my own class?
kindly help me to get a sloution ,
Nov 6 '07 #1
19 2767
r035198x
13,262 8TB
dear all

i am n a situation to display from a int value into Time format,
is there any possiblity of using existing java util classes? or i need to rite my own class?
kindly help me to get a sloution ,
Can you describe your problem more clearly.
What should the output be if the program was given the following
  • 2
  • -1
  • 0
  • 1945
  • 1999876
  • Integer.MAX_VALUE
which are all valid integers?
Nov 6 '07 #2
Can you describe your problem more clearly.
What should the output be if the program was given the following
  • 2
  • -1
  • 0
  • 1945
  • 1999876
  • Integer.MAX_VALUE
which are all valid integers?
Ans:

the valid input in the above list is --> 1945 & the o/p will be like this 7.45 pm


hi ,

the integer value size is 4, ( which i stored in table as Time)
for example

if time is 1500 in table >>
then i have to show , something like this format 3.00 pm in screen
Nov 6 '07 #3
r035198x
13,262 8TB
Ans:

the valid input in the above list is --> 1945 & the o/p will be like this 7.45 pm


hi ,

the integer value size is 4, ( which i stored in table as Time)
for example

if time is 1500 in table >>
then i have to show , something like this format 3.00 pm in screen
Well now don't you think that is a better description of the problem now?
You can write your own method or use the GregorianCalendar class.
Better do this in steps.
First determine whether the input is valid or not (must be positive and must contain 4 digits).
Then split the digits by half into hours and minutes. You can then either set those into a gc to get the am or pm or use a if else to do it yourself manually.
Nov 6 '07 #4
JosAH
11,448 Expert 8TB
Ans:

the valid input in the above list is --> 1945 & the o/p will be like this 7.45 pm
But then the value '2' should be valid as well: two minutes past midnight.
For an int value x, x/100 represents the hours and x%100 represents the
minutes.

kind regards,

Jos
Nov 6 '07 #5
Well now don't you think that is a better description of the problem now?
You can write your own method or use the GregorianCalendar class.
Better do this in steps.
First determine whether the input is valid or not (must be positive and must contain 4 digits).
Then split the digits by half into hours and minutes. You can then either set those into a gc to get the am or pm or use a if else to do it yourself manually.

thanks for the suggestion sir, i will write a method to do this.
Nov 6 '07 #6
r035198x
13,262 8TB
thanks for the suggestion sir, i will write a method to do this.
Have a look at Jos' post above and think about it as well.
It's you who comes up with the rules but make sure your rules are workable. If you restrict the numbers to 4 digits will your program be easy to work with?
Nov 6 '07 #7
Have a look at Jos' post above and think about it as well.
It's you who comes up with the rules but make sure your rules are workable. If you restrict the numbers to 4 digits will your program be easy to work with?

u r correct, if dere s a requirement to include seconds then the size will be 6

in that case for eg : 194512 and i need to format 19:45:12 (hh:mm:ss)

then i have to frame the method....
Nov 6 '07 #8
JosAH
11,448 Expert 8TB
Have a look at Jos' post above and think about it as well.
It's you who comes up with the rules but make sure your rules are workable. If you restrict the numbers to 4 digits will your program be easy to work with?
I'd say four digits or less, more exact the number must be < 2400 for starters.

kind regards,

Jos
Nov 6 '07 #9
r035198x
13,262 8TB
u r correct, if dere s a requirement to include seconds then the size will be 6

in that case for eg : 194512 and i need to format 19:45:12 (hh:mm:ss)

then i have to frame the method....
There we go again ...
Nov 6 '07 #10
JosAH
11,448 Expert 8TB
u r correct, if dere s a requirement to include seconds then the size will be 6

in that case for eg : 194512 and i need to format 19:45:12 (hh:mm:ss)

then i have to frame the method....
I'd say forget about the thing entirely; store date/time values as date/time types
and use a SimpleDateFormatter for the display of it all. That way you don't have
to write your own classes and you can handle everything you ever have to handle.

kind regards,

Jos
Nov 6 '07 #11
r035198x
13,262 8TB
I'd say forget about the thing entirely; store date/time values as date/time types
and use a SimpleDateFormatter for the display of it all. That way you don't have
to write your own classes and you can handle everything you ever have to handle.

kind regards,

Jos
I hope no new information about the problem emerges again ...
Nov 6 '07 #12
JosAH
11,448 Expert 8TB
I hope no new information about the problem emerges again ...
I suspect the OP to be a customer; they always do that and they're driving me crazy ;-)

me: So you're absolutely sure that what I wrote down are all your requirements?
customer: Yes.
me: Really absolutely positively sure? We can go through it one more time again.
customer: not needed, this is it; I'm sure.
me: Really, really, really sure?
customer: yes.
me: Ok fine, I'm glad we settled the entire issue.
customer: me too, I'm glad we can take the next step.
me: yup, see you next week then.
customer: yes, fine; oh, btw we decided that we want all the menus coloured green
and while I'm at it the application should automagically smell that we want the reports
to be produced even if we haven't supplied all data yet and we want the application
to be able to start Solitaire as well, but only for my account. And my nephew told
me that Java sucks so we don't want that; we do want J2EE technology instead
because we're a modern company. And we want Oracle as well instead of DB2.
On a floppy disk please so I can take it home with me for security reasons.

<curtain/>

kind regards,

Jos ;-)
Nov 6 '07 #13
I suspect the OP to be a customer; they always do that and they're driving me crazy ;-)

me: So you're absolutely sure that what I wrote down are all your requirements?
customer: Yes.
me: Really absolutely positively sure? We can go through it one more time again.
customer: not needed, this is it; I'm sure.
me: Really, really, really sure?
customer: yes.
me: Ok fine, I'm glad we settled the entire issue.
customer: me too, I'm glad we can take the next step.
me: yup, see you next week then.
customer: yes, fine; oh, btw we decided that we want all the menus coloured green
and while I'm at it the application should automagically smell that we want the reports
to be produced even if we haven't supplied all data yet and we want the application
to be able to start Solitaire as well, but only for my account. And my nephew told
me that Java sucks so we don't want that; we do want J2EE technology instead
because we're a modern company. And we want Oracle as well instead of DB2.
On a floppy disk please so I can take it home with me for security reasons.

<curtain/>

kind regards,

Jos ;-)

dear all

sorry for the late reply....as i cant change ma existing data type since its an production data...only thing writing own class..
Moreover i m a new bie , so slow to get the things...

thanks for replies
Nov 7 '07 #14
JosAH
11,448 Expert 8TB
dear all

sorry for the late reply....as i cant change ma existing data type since its an production data...only thing writing own class..
Moreover i m a new bie , so slow to get the things...

thanks for replies
Ok, so a date/time value is stored as an int. So far so good; What exactly is
stored in that int? The time of the day? Are seconds, milliseconds included?
We need to specify exactly what is in that int and how time is encoded as an
int value before we can start designing or even implementing fancy classes.

Right now we haven't even touched the specification/requirement stage which
has to be completed before we can even design something.

kind regards,

Jos
Nov 7 '07 #15
Ok, so a date/time value is stored as an int. So far so good; What exactly is
stored in that int? The time of the day? Are seconds, milliseconds included?
We need to specify exactly what is in that int and how time is encoded as an
int value before we can start designing or even implementing fancy classes.

Right now we haven't even touched the specification/requirement stage which
has to be completed before we can even design something.

kind regards,

Jos
Field Size
Time 6


In that case for eg : This value s stored from other program based on some conditions

Value for this field is 194512 in table and display will be either of the one below , i am not sure which one s appropriate or easy to show from the below formats

19:45:12 (hh:mm:ss)
or
07:45 pm

kindly suggest me

thnks
Nov 7 '07 #16
r035198x
13,262 8TB
Field Size
Time 6


In that case for eg : This value s stored from other program based on some conditions

Value for this field is 194512 in table and display will be either of the one below , i am not sure which one s appropriate or easy to show from the below formats

19:45:12 (hh:mm:ss)
or
07:45 pm

kindly suggest me

thnks
You mean the field size is 6 or less?
I suggest you work on the allowable input first and how it maps to time. Displaying in 12 hour or 24 hour is easily done as the the last exercise.
Nov 7 '07 #17
You mean the field size is 6 or less?
I suggest you work on the allowable input first and how it maps to time. Displaying in 12 hour or 24 hour is easily done as the the last exercise.

actually that time s stored by a cobol prgm , where its updating table with 6 digits

TIME 9(006)

but when i look in sybase table desciption its showing the following

TIME int 4

also all d data i am having for this field n sybase shows

TIME 194512

so confused to tell u the correct size sir!!!!!!!!!
Nov 7 '07 #18
JosAH
11,448 Expert 8TB
But if the decimal representation of the number is equal to, say, the display of
a digital clock, all you have to do is something like this:

Expand|Select|Wrap|Line Numbers
  1. DecimalFormat df= new DecimalFormat("00,00,00");
  2. DecimalFormatSymbols dfs= new DecimalFormatSymbols();
  3. dfs.setGroupingCharacter(':');
  4. df.setDecimalFomatSymbols(dfs);
  5. ...
  6. // and format away using df and your int values
  7.  
kind regards,

Jos

ps. read the API documentation for those classes; most likely I made a few
typos above; it was from the top of my head.
Nov 7 '07 #19
But if the decimal representation of the number is equal to, say, the display of
a digital clock, all you have to do is something like this:

Expand|Select|Wrap|Line Numbers
  1. DecimalFormat df= new DecimalFormat("00,00,00");
  2. DecimalFormatSymbols dfs= new DecimalFormatSymbols();
  3. dfs.setGroupingCharacter(':');
  4. df.setDecimalFomatSymbols(dfs);
  5. ...
  6. // and format away using df and your int values
  7.  
kind regards,

Jos

ps. read the API documentation for those classes; most likely I made a few
typos above; it was from the top of my head.
thnks for the suggestions sir, really it will be a grt help to me

Best Regards...
Nov 7 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marcus | last post by:
I was wondering if someone could help explain how an integer could be transformed into a time format. For instance I have an integer 62446 which should read 17:xx:xx or hhmmss (The colon seperators...
22
by: hantie | last post by:
In my program, for reducing the complexity, the integer was stored as char, so 2 is stored as '2', which is decimal: 50 Is is possible for me to obtain the integer value of '2' in the program,...
5
by: Julia | last post by:
Hi I have changed my regional options on my computer to English (United States) (I used to have Swedish). I would print the value of the current time in a textbox on my asp.net page. I use this...
7
by: WorldIsEnding | last post by:
Hey, Im having trouble with converting a Numeric value (such as a single digit number like 1 or 5) into a time format. I need to convert a number entered into a variable into Hours on the...
3
by: R69D | last post by:
Hi, I'm real new to Java and need some help...was going through some old tutorials and need help with these questions: 1)What is “composition of methods?” How do u define the composition of...
6
by: ponvijaya | last post by:
hi all, I have time stored in my table field as hh:mm am or pm (eg 04:15 PM , 02:30 AM). The field is of type varchar. I need to convert it as a MySql time format. Can any body help...
23
by: tatata9999 | last post by:
Hi, What time zones tend to use 24 hours time format? Googling hasn't been able to answer the question. Thank you.
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.