Kentico DateTime WebPart not working with Custom TimeZone

Vuthy Sok asked on August 10, 2018 06:49

Hi guys,,

I have setup kentico 11 I want to show time difference from my local time. I have used DateTime Webpart but time still get from my local time. My configure in WebPart

Date and time format: HH:MM TT, mmmm dd , yyyy
Time zone: Custom
Custom time zone: (UTC+04.00) Abu Dhabi, Muscat

I would appreciate any help fix issue.

Thank you in advance!!

Correct Answer

Vuthy Sok answered on August 13, 2018 06:38

Now I got resolve my problem

{% String.FormatString("{0:hh:mm tt, MMMM d, yyyy}", DateTime.UtcNow.AddHours(4)) |(identity)GlobalAdministrator%}

0 votesVote for this answer Unmark Correct answer

Recent Answers


Arun Kumar answered on August 10, 2018 08:41 (last edited on August 10, 2018 08:42)

If you just want to show time then you can use a custom macro which will convert the current time to custom timezone using C# date time conversions and use that macro in your page to display date time.

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on August 10, 2018 16:11

That webpart just displays the current date and time. Are you wanting to display the server time?

0 votesVote for this answer Mark as a Correct answer

Vuthy Sok answered on August 13, 2018 03:45

Thanks for reply.

Arun Kumar, Is any ways don't use custom C# code.

Zach Perry, I want display time via Time Zone. Example I live at Cambodia and I want to display "Abu Dhabi, Muscat".

0 votesVote for this answer Mark as a Correct answer

Arun Kumar answered on August 13, 2018 06:41 (last edited on August 13, 2018 06:41)

You can use simple JavaScript webpart with below code in it:

window.onload=function(){ 
var d = new Date();
var offset="+4.0";
var city="Abu";
// convert to msec
// subtract local time zone offset
// get UTC time in msec
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);

// create new Date object for different city
// using supplied offset
var nd = new Date(utc + (3600000*offset));

// return time as a string
//alert ("The local time for city"+ city +" is "+ nd.toLocaleString());
document.getElementById("lblDate").value=nd.toLocaleString();
};

lblDate here is label on the page where you want to display this date.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.