Contents
- Show or hide timestamp
- Setting timestamp format
Having trouble getting help?
Contact Support
Contact Support
Timestamp in ASP.NET MVC Chat UI control
16 Dec 20245 minutes to read
Show or hide timestamp
You can use the ShowTimeStamp property to enable or disable timestamps for all messages which displays the exact date and time when they were sent. By default, the value is true
.
@using Syncfusion.EJ2.InteractiveChat;
@using Newtonsoft.Json;
<div class="chatui-container" style="height:380px; width:450px">
@Html.EJS().ChatUI("chatUser").ShowTimeStamp(false).Created("onCreated").User(ViewBag.CurrentUser).Render()
</div>
<script>
var chatUIObj;
var chatMessages = @Html.Raw(JsonConvert.SerializeObject(ViewBag.ChatMessagesData));
chatMessages.forEach(message => {
message.timeStamp = new Date(message.timeStamp);
});
function onCreated() {
var chatUiEle = document.getElementById('chatUser');
chatUIObj = ej.base.getInstance(chatUiEle, ejs.interactivechat.ChatUI);
chatUIObj.messages = chatMessages;
chatUIObj.dataBind();
}
</script>
using Syncfusion.EJ2.InteractiveChat;
public ChatUIUser CurrentUser { get; set; }
public List<ChatUIMessage> ChatMessagesData { get; set; } = new List<ChatUIMessage>();
public ChatUIUser CurrentUserModel { get; set; } = new ChatUIUser() { Id = "user1", User = "Albert" };
public ChatUIUser MichaleUserModel { get; set; } = new ChatUIUser() { Id = "user2", User = "Michale Suyama" };
public ActionResult Timestamp()
{
CurrentUser = CurrentUserModel;
ChatMessagesData.Add(new ChatUIMessage()
{
Text = "Hi Michale, are we on track for the deadline?",
Author = CurrentUserModel,
TimeStamp = new DateTime(2024,12,25,7,30,0)
});
ChatMessagesData.Add(new ChatUIMessage()
{
Text = "Yes, the design phase is complete.",
Author = MichaleUserModel,
TimeStamp = new DateTime(2024,12,25,8,0,0)
});
ChatMessagesData.Add(new ChatUIMessage()
{
Text = "I’ll review it and send feedback by today.",
Author = CurrentUserModel,
TimeStamp = new DateTime(2024,12,25,11,0,0)
});
ViewBag.ChatMessagesData = ChatMessagesData;
ViewBag.CurrentUser = CurrentUser;
return View();
}
Setting timestamp format
You can use the TimeStampFormat property to display time formats for all the messages which are displayed with the messages being sent. By default, the value is dd/MM/yyyy hh:mm a
.
@using Syncfusion.EJ2.InteractiveChat
<div class="chatui-container" style="height:380px; width:450px">
@Html.EJS().ChatUI("chatUser").Messages(ViewBag.ChatMessagesData).User(ViewBag.CurrentUser).TimeStampFormat("MMMM hh:mm a").Render()
</div>
using Syncfusion.EJ2.InteractiveChat;
public ChatUIUser CurrentUser { get; set; }
public List<ChatUIMessage> ChatMessagesData { get; set; } = new List<ChatUIMessage>();
public ChatUIUser CurrentUserModel { get; set; } = new ChatUIUser() { Id = "user1", User = "Albert" };
public ChatUIUser MichaleUserModel { get; set; } = new ChatUIUser() { Id = "user2", User = "Michale Suyama" };
public ActionResult TimestampFormat()
{
CurrentUser = CurrentUserModel;
ChatMessagesData.Add(new ChatUIMessage()
{
Text = "Hi Michale, are we on track for the deadline?",
Author = CurrentUserModel
});
ChatMessagesData.Add(new ChatUIMessage()
{
Text = "Yes, the design phase is complete.",
Author = MichaleUserModel
});
ChatMessagesData.Add(new ChatUIMessage()
{
Text = "I’ll review it and send feedback by today.",
Author = CurrentUserModel
});
ViewBag.ChatMessagesData = ChatMessagesData;
ViewBag.CurrentUser = CurrentUser;
return View();
}