Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

TimeZoneInfo doesn't find time zones on Unity

Discussion in 'Scripting' started by Mark-De-Clare, Jun 27, 2015.

  1. Mark-De-Clare

    Mark-De-Clare

    Joined:
    Aug 9, 2011
    Posts:
    63
    Why TimeZoneInfo (found in system namespace) doesn't find time zones on Unity? Doesn't mono support it? I'm using Windows.
    The following code prints only 0:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. using System.Collections.ObjectModel;
    5. public class Timezones : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.         Debug.Log(TimeZoneInfo.GetSystemTimeZones().Count);
    10.         foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
    11.             Debug.Log(z.Id);
    12.         ReadOnlyCollection<TimeZoneInfo> tzCollection;
    13.         tzCollection = TimeZoneInfo.GetSystemTimeZones();
    14.         foreach (TimeZoneInfo timeZone in tzCollection){
    15.             print(timeZone.Id+":"+ timeZone.DisplayName);
    16.         }
    17.     }
    18.  
    19. }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. Mark-De-Clare

    Mark-De-Clare

    Joined:
    Aug 9, 2011
    Posts:
    63
    I couldn't find timeZoneInfo class from mono compatibility page, so I guess it's not compatible with Unity. I don't need local currenttimezone, i need to get any timezone from TimeZoneInfo.