---
title: Displaying correct time in your code
related:
  - https://docs.kentico.com/k10/configuring-kentico/configuring-time-zones.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

You can use the following methods in the code of [ASCX transformations](https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/writing-transformations.md) to display the correct time according to time zone settings.

|   | Returns date-time value according to web part time zone settings.           |
| - | --------------------------------------------------------------------------- |
|   | Returns date-time according to site time zone settings.                     |
|   | Returns date-time according to the current user's time zone settings.       |
|   | Returns date-time according to the time zone given in the second parameter. |

### Example

The following example demonstrates how to use the **User control** web part to display the current date and time on your site, according to the time zone settings of the web part.

1. Open your web project in Visual Studio
2. Add a folder named **CMSGlobalFiles** (if it doesn't already exist).
3. Create a new **Web User Control** in the folder named _datetime.ascx_.
4. Add a **Label** control onto the user control's form.
5. Edit the control's code behind and add the following code to the **Page\_Load** method:

   ```csharp

   Label1.Text = CMS.Globalization.Web.UI.TimeZoneUIMethods.ConvertDateTime(DateTime.Now, this).ToString();

   ```
6. Log in to the Kentico administration interface.
7. Open the **Pages** applications and edit a page on the **Design** tab.
8. [Add](https://docs.kentico.com/k10/developing-websites/developing-websites-using-the-portal-engine/using-and-configuring-web-parts.md) the **User control** web part onto the page.
9. Set the following properties of the web part:
   - **User control virtual path:** _\~/cmsglobalfiles/datetime.ascx_
   - **Time zone**: _Custom_
   - **Custom time zone**: any time zone of your choice
10. Click **OK**.

If you switch to the live site, you can see the web part displaying the current date and time in the selected time zone. You can also try changing the value of the **Custom time zone** property and verify that the time displayed on the live site changes accordingly.
