Fan.Sys.TimeZone.fromGmtOffset C# (CSharp) Méthode

fromGmtOffset() public static méthode

public static fromGmtOffset ( int offset ) : TimeZone
offset int
Résultat TimeZone
        public static TimeZone fromGmtOffset(int offset)
        {
            if (offset == 0)
            return TimeZone.utc();
              else
            return TimeZone.fromStr("GMT" + (offset < 0 ? ("+" + (-offset/3600)) : ("-" + (offset/3600))));
        }

Usage Example

Exemple #1
0
        //////////////////////////////////////////////////////////////////////////
        // Parse
        //////////////////////////////////////////////////////////////////////////

        internal DateTime parseDateTime(string s, TimeZone defTz, bool check)
        {
            try
            {
                // parse into fields
                tzOffset = System.Int32.MaxValue;
                parse(s);

                // now figure out what timezone to use
                TimeZone.Rule defRule = defTz.rule(year);
                if (tzName != null)
                {
                    // use defTz if tzName was specified and matches any variations of defTz
                    if (tzName == defTz.name() ||
                        tzName == defRule.stdAbbr ||
                        tzName == defRule.dstAbbr)
                    {
                        tz = defTz;
                    }

                    // try to map tzName to TimeZone, use defTz as fallback
                    else
                    {
                        tz = TimeZone.fromStr(tzName, false);
                        if (tz == null)
                        {
                            tz = defTz;
                        }
                    }
                }

                // if tzOffset was specified...
                else if (tzOffset != System.Int32.MaxValue)
                {
                    // figure out what expected offset was for defTz
                    int time      = hour * 3600 + min * 60 + sec;
                    int defOffset = defRule.offset + TimeZone.dstOffset(defRule, year, (int)mon.ordinal(), day, time);

                    // if specified offset matches expected offset for defTz then
                    // use defTz, otherwise use a vanilla GMT+/- timezone
                    if (tzOffset == defOffset)
                    {
                        tz = defTz;
                    }
                    else
                    {
                        tz = TimeZone.fromGmtOffset(tzOffset);
                    }
                }

                // no tzName or tzOffset specified, use defTz
                else
                {
                    tz = defTz;
                }

                // construct DateTime
                return(new DateTime(year, (int)mon.ordinal(), day, hour, min, sec, ns, tzOffset, tz));
            }
            catch (Exception) {}
            if (check)
            {
                throw ParseErr.make("DateTime", s).val;
            }
            return(null);
        }
All Usage Examples Of Fan.Sys.TimeZone::fromGmtOffset