/// <summary> /// Getting time or date from url (default jsontest) /// Dont use on Update or FixedUpdate /// </summary> /// <param name="type">The return type, pmam returns 0 if AM and 1 if PM</param> /// <param name="pmam">Whether to use the AM PM system</param> /// <param name="from">To specify another url, !WARNING! JSON must has "time" as string, "milliseconds_since_epoch" as int and "date" as string</param> public static DateTime getTime(string from = "http://date.jsontest.com/") { string getting = EasyDo.GetWWWString(from, true); if (string.IsNullOrEmpty(getting)) { return(DateTime.Today); } RealTimeCallback rt = new RealTimeCallback(); try { rt = JsonUtility.FromJson <RealTimeCallback>(getting); return(DateTime.Parse(rt.date + " " + rt.time)); } catch (Exception ex) { return(DateTime.Today); } }
/// <summary> /// Getting time or date from url (default jsontest) /// Dont use on Update or FixedUpdate /// </summary> /// <param name="type">The return type, pmam returns 0 if AM and 1 if PM</param> /// <param name="pmam">Whether to use the AM PM system</param> /// <param name="from">To specify another url, !WARNING! JSON must has "time" as string, "milliseconds_since_epoch" as int and "date" as string</param> public static int getTime(TimeType type, bool pmam = false, string from = "http://date.jsontest.com/") { string getting = ""; getting = EasyDo.GetWWWString(from, true); if (string.IsNullOrEmpty(getting)) { return(0); } RealTimeCallback rt = new RealTimeCallback(); rt = JsonUtility.FromJson <RealTimeCallback>(getting); DateTime date = DateTime.Parse(rt.date + " " + rt.time); if (type == TimeType.day) { return(date.Day); } if (type == TimeType.mounth) { return(date.Month); } if (type == TimeType.year) { return(date.Year); } if (type == TimeType.sec) { return(date.Second); } if (type == TimeType.min) { return(date.Minute); } if (type == TimeType.hour) { if (rt.time[9].ToString() + rt.time[10].ToString() == "PM" && !pmam) { return(int.Parse(rt.time[0].ToString() + rt.time[1].ToString()) + 12); } else { return(int.Parse(rt.time[0].ToString() + rt.time[1].ToString())); } } if (type == TimeType.pmam) { if (rt.time[9].ToString() + rt.time[10].ToString() == "PM") { return(1); } else { return(0); } } return(0); }