Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
How to convert time to string in android.
Means my time is 13:00:00 and i want to convert it into 1pm.
time come from databse.

What I have tried:

select Convert(varchar(15),CAST(Time AS TIME),100) from table_Name
Posted
Updated 2-Jun-18 6:47am
Comments
Richard MacCutchan 2-Jun-18 6:28am    
What result do you see?
David Crow 3-Jun-18 17:59pm    
Have you tried something like:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date date = sdf.parse("13:00:00");
System.out.println(new SimpleDateFormat("ha").format(date));
Member 13809462 4-Jun-18 3:29am    
Hello, but my time is come from database and in database time is 13:00:00 i want to convert time when i fetch from database to am and pm.
Thank u.
David Crow 4-Jun-18 22:51pm    
You've been given an Android answer and a SQL answer, neither of which you've liked. Are you sure you know exactly what you are looking for?

1 solution

Your query returns 1:00PM, which is very close to your desired 1PM. There doesn't appear to be a built-in date format for that, but you can use REPLACE(..., ':00', '') to achieve it:
SQL
SELECT REPLACE(CONVERT(varchar(15), Cast(Time AS TIME), 100), ':00', '') from table_Name
 
Share this answer
 
Comments
Member 13809462 4-Jun-18 3:30am    
Hello, but my time is come from database and in database time is 13:00:00 i want to convert time when i fetch from database to am and pm.
Thank u.
Thomas Daniels 4-Jun-18 11:32am    
Yes, that's what my answer should do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900