How to change the TimeFormat of each message to 24 hours?

I am using SendBirdUIkit for app developement and want to change the 12 hours time format to 24 hours


[UIKit Version]
UIkit version :- 3.4.5

minmum:-23
maxmium:- 33

Hello @Mayank_Ingle ,

Welcome to Sendbird community!

To change the time format from 12 hours to 24 hours in UIKit v3.4.5, you can use the setTimeFormat() method from the SBUIMessageCell class. Here’s an example of how to do it:

→ import SendBirdUIKit
→ SBUIMessageCell.setTimeFormat(.twentyFourHours)`

This will set the time format to 24 hours for all message cells in your UIKit application.

i want solution for android in java

To change the time format of each message from 12 hours to 24 hours in Android using Java, you can use the SimpleDateFormat class. Here’s an example code snippet:

// Assuming you have a message object with a timestamp
Message message = getMessage();

// Create a SimpleDateFormat object with the desired format
SimpleDateFormat inputFormat = new SimpleDateFormat(“hh:mm a”, Locale.getDefault());
SimpleDateFormat outputFormat = new SimpleDateFormat(“HH:mm”, Locale.getDefault());

// Parse the timestamp using the input format
Date date = inputFormat.parse(message.getTimestamp());

// Format the timestamp using the output format
String formattedTime = outputFormat.format(date);

// Set the formatted time to your UI element
textView.setText(formattedTime);

In this example, we first create two SimpleDateFormat objects: inputFormat for parsing the timestamp in the 12-hour format, and outputFormat for formatting the timestamp in the 24-hour format.

Then, we parse the timestamp using the inputFormat and obtain a Date object. We format this Date object using the outputFormat to get the desired 24-hour formatted time.

Finally, you can set the formatted time to your UI element, such as a TextView.

Let me know if this helps.

thanks for the answers but i need to implement it directly since am not able to get the specific textview for time and date display on ChannelFragment which is customized.

Hi @Mayank_Ingle,

By default, Android uses the device’s system settings for date/time format, which is based on the user’s preferred language and region.

To display dates and times in a specific format in your Android app, you can use the SimpleDateFormat class to format the date/time according to your desired pattern. You can specify the pattern using a combination of letters and symbols that represent different components of the date/time.
Here’s an example of how you can format a date/time using a specific pattern:

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String formattedDateTime = sdf.format(new Date());

You can customize the pattern according to your needs.
Remember to handle any potential exceptions when working with date/time formatting in Android, such as ParseException when parsing a string into a date/time object or IllegalArgumentException when an invalid pattern is provided.

Let me know if it helps.