如何将Android日历设置为航海或军事时区。

huangapple go评论77阅读模式
英文:

How do I set the Android Calendar to nautical or military timezones

问题

在我的Android应用中,我在各种不同的时区使用日历。这样,我可以根据当地条件调整应用的操作。

runDate = Calendar.getInstance(); // 将显示这个日期/时间的潮汐
useThisTZ = TimeZone.getTimeZone("US/Pacific");
runDate.setTimeZone(useThisTZ);

我需要适应航海或军事时区。这些时区是地理时区,而不是民用时区。我需要确定我可以传递给getTimeZone函数的时区标识符。我尝试过时区代码"A",它标识了阿尔法时区(UTC + 1)。然而,这将日历放置在了GMT时区,通常被称为Zulu时区。
有人知道这些标识符是否可用,以及可能是什么标识符吗?

英文:

In my Android app, I use the calendar in various time zones. This way I can adjust the app operation
to local conditions.

runDate = Calendar.getInstance(); // will display tides for this date/time
useThisTZ = TimeZone.getTimeZone("US/Pacific");
runDate.setTimeZone(useThisTZ);

I need to adapt to nautical or military time zones. These are geographic rather than civil. I need to determine what identifiers I can pass into the getTimeZone function to do this. I have tried the time zone code "A" which identified the Alpha time zone (UTC + 1). However this placed the calendar into
the GMT zone which would normally be called Zulu.

Does anybody know if these identifiers are available and what they might be.

答案1

得分: 1

java.time 中的 ZoneOffsetOffsetDateTime

考虑在处理日期和时间时使用现代的 Java 日期和时间 API,即 java.time。航海(或军事)时区只是与协调世界时(UTC)相差整数小时的偏移量,因此我们不需要考虑夏令时(DST)和其他异常的复杂时区规则,因为这些都不存在。简单的 ZoneOffset 就足够了。

时区名称并不是内置的,我们需要自己编写转换代码。一种方法是通过一个数组,在其中可以查找时区名称并获取偏移量:

private static final int[] offsetPerNauticalTimeZone = new int['Z' + 1];
private static final int invalid = -100;
static {
    Arrays.fill(offsetPerNauticalTimeZone, invalid);
    // 字母 "Z" 表示协调世界时 (UTC)。
    offsetPerNauticalTimeZone['Z'] = 0;
    // A 到 M 表示正偏移,但跳过 J
    for (int offset = 1; offset <= 9; offset++) {
        offsetPerNauticalTimeZone['A' - 1 + offset] = offset;
    }
    for (int offset = 10; offset <= 12; offset++) {
        offsetPerNauticalTimeZone['K' - 10 + offset] = offset;
    }
    // N 到 Y 表示负偏移
    for (int negatedOffset = 1; negatedOffset <= 12; negatedOffset++) {
        offsetPerNauticalTimeZone['N' - 1 + negatedOffset] = -negatedOffset;
    }
}

示例用法:

char nauticalTimeZone = 'A'; // 在这里设置所需的字母

int offsetHours = offsetPerNauticalTimeZone[nauticalTimeZone];
if (offsetHours == invalid) {
    System.out.println("Invalid nautical time zone " + nauticalTimeZone);
} else {
    ZoneOffset offset = ZoneOffset.ofHours(offsetHours);
    OffsetDateTime runDateTime = OffsetDateTime.now(offset);

    System.out.println(runDateTime);
}

当我刚刚运行这段代码时,输出为:

> 2020-09-23T20:05:52.451+01:00

你会注意到偏移量是 +01:00,对应于航海时区 A。请尝试其他时区。

目前的代码在字符超出大写字母 "Z" 时会抛出 ArrayIndexOutOfBoundsException。你需要添加必要的检查逻辑。

编辑:

嗯,我正在使用的日历代码接受时区名称。我只需要一个完整的列表。

如果是我,我会借此机会从过时的 Calendar 类切换到 java.time。而且,正如我试图指出的,当你使用老式的 TimeZone 类时,你携带了所有需要用于一般时区的东西,而实际上你只需要一个偏移量。如果你坚持使用 Calendar 并为其提供一个 TimeZone,转换是相当简单的。假设你使用的是 ThreeTenABP(参见下面):

TimeZone oldFashionedTimeZone = DateTimeUtils.toTimeZone(offset);
System.out.println(oldFashionedTimeZone.getID());

输出为:

> GMT+01:00

这就是你要求的时区 ID。其他的类似,你可以自己构建它们。如果有疑问,可以运行我的代码并从中获取。对于输入到 Calendar 中,你实际上并不需要这个 ID,因为你已经有了 TimeZone 对象。

即使对于遗留代码需要使用老式的 Calendar,情况仍会稍微好一些(或者说不那么糟糕),因为你不需要处理混乱且设计不佳的 TimeZone 类。你可以从以下代码中获取你的 Calendar

Calendar runDate = DateTimeUtils.toGregorianCalendar(
        runDateTime.atZoneSameInstant(offset));

如果使用 Java 8(或者使用 Java 8 通过 desugaring 的方式,我猜),转换还会更加简短,分别是 TimeZone.getTimeZone(offset)GregorianCalendar.from(runDateTime.atZoneSameInstant(offset))

问题:java.time 需要 Android API 等级 26 吗?

java.time 在旧版和新版 Android 设备上都可以很好地工作。它只需要至少 Java 6

  • 在 Java 8 及更高版本和新版 Android 设备(从 API 等级 26 开始),这个现代 API 是内置的。
  • 在非 Android 环境的 Java 6 和 7 中,可以使用 ThreeTen Backport,即现代类的后移版本(ThreeTen for JSR 310;参见底部的链接)。
  • 在旧版 Android 中,可以使用 desugaring 或 ThreeTen Backport 的 Android 版本,称为 ThreeTenABP。在后一种情况下,请确保从 org.threeten.bp 及其子包中导入日期和时间类。

链接

英文:

ZoneOffset and OffsetDateTime from java.time

Consider using java.time, the modern Java date and time API, for your date and time work. Nautical (or military) time zones are mere offsets in whole hours from UTC, so we don’t need any fancy time zone rules taking summer time (DST) and other anomalies into account, for there aren’t any. A plain ZoneOffset will do.

The time zone names are not built in. We need to code the conversion ourselves. One way to do it is through an array in which we can look up a time zone name and get the offset out:

private static final int[] offsetPerNauticalTimeZone = new int[&#39;Z&#39; + 1];
private static final int invalid = -100;
static {
	Arrays.fill(offsetPerNauticalTimeZone, invalid);
	// The letter &quot;Z&quot; (&quot;Zulu&quot;) indicates Coordinated Universal Time (UTC). 
	offsetPerNauticalTimeZone[&#39;Z&#39;] = 0;
	// A through M denote positive offsets, but J is skipped
	for (int offset = 1; offset &lt;= 9; offset++) {
		offsetPerNauticalTimeZone[&#39;A&#39; - 1 + offset] = offset;
	}
	for (int offset = 10; offset &lt;= 12; offset++) {
		offsetPerNauticalTimeZone[&#39;K&#39; - 10 + offset] = offset;
	}
	// N through Y are the negative offsets
	for (int negatatedOffset = 1; negatatedOffset &lt;= 12; negatatedOffset++) {
		offsetPerNauticalTimeZone[&#39;N&#39; - 1 + negatatedOffset] = -negatatedOffset;
	}
}

Example use:

	char nauticalTimeZone = &#39;A&#39;; // Set desired letter here
	
	int offsetHours = offsetPerNauticalTimeZone[nauticalTimeZone];
	if (offsetHours == invalid) {
		System.out.println(&quot;Invalid nautical time zone &quot; + nauticalTimeZone);
	} else {
		ZoneOffset offset = ZoneOffset.ofHours(offsetHours);
		OffsetDateTime runDateTime = OffsetDateTime.now(offset);
		
		System.out.println(runDateTime);
	}

When I ran this snippet just now, the output was:

> 2020-09-23T20:05:52.451+01:00

You notice that the offset is +01:00 corresponding to nautical time zone A. Please try the other time zones too.

As the code stands it will throw anArrayIndexOutOfBounsException if the char is beyond upper case Z. I leave it to you to build in the necessary check.

Edit:

> Well, the calendar code I am using does accept time zone names. I just
> need a complete list of what those are.

If that were me, I would take the opportunity to switch over from the outdated Calendar class to java.time. Also because, as I tried to indicate, when you use the old-fashioned TimeZone class, you are carrying with you everything that is needed for general time zones when all you need is an offset. If you insist on using Calendar and feeding it a TimeZone, the conversion is easy enough. Assuming your are using ThreeTenABP (see below):

		TimeZone oldfashionedTimeZone = DateTimeUtils.toTimeZone(offset);
		System.out.println(oldfashionedTimeZone.getID());

> GMT+01:00

This is the time zone ID you were asking for. The others are similar, you can construct them yourself. If in doubt, run my code at get them from there. For feeding into a Calendar you don’t need the ID, of course, you have already got the TimeZone object.

Still a bit better (or not quite so bad), even if you need an old-fashioned Calendar for your legacy code, you don’t need to deal with the confusing and poorly designed TimeZone class. You may get your Calendar from this code:

		Calendar runDate = DateTimeUtils.toGregorianCalendar(
				runDateTime.atZoneSameInstant(offset));

If using Java 8 (also if using Java 8 through desugaring, I suppose), the conversions are a bit shorter still, TimeZone.getTimeZone(offset) and GregorianCalendar.from(runDateTime.atZoneSameInstant(offset)), respectively.

Question: Doesn’t java.time require Android API level 26?

java.time works nicely on both older and newer Android devices. It just requires at least Java 6.

  • In Java 8 and later and on newer Android devices (from API level 26) the modern API comes built-in.
  • In non-Android Java 6 and 7 get the ThreeTen Backport, the backport of the modern classes (ThreeTen for JSR 310; see the links at the bottom).
  • On older Android either use desugaring or the Android edition of ThreeTen Backport. It’s called ThreeTenABP. In the latter case make sure you import the date and time classes from org.threeten.bp with subpackages.

答案2

得分: 0

我会使用现代的日期时间API(正如Ole V.V.所建议的)。然而,看起来你想要使用传统的日期时间API来完成这个。我脑海中浮现出的一个解决方案是构建一个将军事时区映射到标准时区的Map,就像这里提到的那样。之后,你可以使用军事时区字母(例如ABC等)来显示该时区的日期时间。

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

public class Main {
    public static void main(String[] args) {
        Map<String, String> tzMap = new HashMap<>();
        tzMap.put("A", "Europe/Paris");
        tzMap.put("B", "Europe/Athens");
        tzMap.put("C", "Europe/Moscow");
        // 以此类推...

        // 测试
        Calendar calendar = Calendar.getInstance();
        displayDateInMilitaryTZ(calendar, tzMap.get("A"));
        displayDateInMilitaryTZ(calendar, tzMap.get("B"));
        displayDateInMilitaryTZ(calendar, tzMap.get("C"));
    }

    static void displayDateInMilitaryTZ(Calendar runDate, String tz) {
        TimeZone useThisTZ = TimeZone.getTimeZone(tz);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(useThisTZ);
        System.out.println(sdf.format(runDate.getTime()));
    }
}

输出:

2020-09-23 23:33:16
2020-09-24 00:33:16
2020-09-24 00:33:16
英文:

I would use the modern date-time API as suggested by Ole V.V.. However, it looks like you want to do it using the legacy date-time API. A solution that comes to my mind is to build a Map of military time-zones mapped to the civil time-zones e.g. as mentioned here. After that, you can use the military time-zone letter (e.g. A, B, C etc.) to display date-time in the that time-zone.

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

public class Main {
	public static void main(String[] args) {
		Map&lt;String, String&gt; tzMap = new HashMap&lt;&gt;();
		tzMap.put(&quot;A&quot;, &quot;Europe/Paris&quot;);
		tzMap.put(&quot;B&quot;, &quot;Europe/Athens&quot;);
		tzMap.put(&quot;C&quot;, &quot;Europe/Moscow&quot;);
		// and so on...

		// Tests
		Calendar calendar = Calendar.getInstance();
		displayDateInMilitaryTZ(calendar, tzMap.get(&quot;A&quot;));
		displayDateInMilitaryTZ(calendar, tzMap.get(&quot;B&quot;));
		displayDateInMilitaryTZ(calendar, tzMap.get(&quot;C&quot;));
	}

	static void displayDateInMilitaryTZ(Calendar runDate, String tz) {
		TimeZone useThisTZ = TimeZone.getTimeZone(tz);
		SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss&quot;);
		sdf.setTimeZone(useThisTZ);
		System.out.println(sdf.format(runDate.getTime()));
	}
}

Output:

2020-09-23 23:33:16
2020-09-24 00:33:16
2020-09-24 00:33:16

答案3

得分: 0

以下是您提供的Java代码的翻译部分:

runDate = Calendar.getInstance();

// 根据经度选择时区
// 西经为负经度,范围从 0 到 -180
// 东经为正经度,范围从 0 到 +180
// 下面的逻辑从格林威治向东处理

if ((longitude > -7.5) && (longitude < 7.5)) // UTC+0
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+0"); tzName = "Zulu"; }

else if ((longitude > 7.5) && (longitude < 22.5)) // UTC+1
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-1"); tzName = "Alpha"; }

else if ((longitude > 22.5) && (longitude < 37.5)) // UTC+2
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-2"); tzName = "Bravo"; }

else if ((longitude > 37.5) && (longitude < 52.50)) // UTC+3
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-3"); tzName = "Charlie"; }

else if ((longitude > 52.5) && (longitude < 67.5)) // UTC+4
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-4"); tzName = "Delta"; }

else if ((longitude > 67.5) && (longitude  < 82.5)) // UTC+5
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-5"); tzName = "Echo"; }

else if ((longitude > 82.5) && (longitude < 97.5)) // UTC+6
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-6"); tzName = "Foxtrot"; }

else if ((longitude > 97.5) && (longitude < 112.5)) // UTC+7
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-7"); tzName = "Golf"; }

else if ((longitude > 112.5) && (longitude < 127.5)) // UTC+8
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-8"); tzName = "Hotel"; }

else if ((longitude > 127.5) && (longitude < 142.5)) // UTC+9
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-9"); tzName = "India"; }

else if ((longitude > 142.5) && (longitude < 157.5)) // UTC+10
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-10"); tzName = "Kilo"; }

else if ((longitude > 157.5) && (longitude < 172.5)) // UTC+11
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-11"); tzName = "Lima"; }

else if ((longitude > 172.5) && (longitude < 180)) // UTC+12,7.5 度宽
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT-12"); tzName = "Mike"; }

else if ((longitude > -180) && (longitude < -172.5)) // UTC-12,7.5 度宽
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+12"); tzName = "Yankee"; }

else if ((longitude > -172.5) && (longitude < -157.5)) // UTC-11
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+11"); tzName = "X-Ray"; }

else if ((longitude > -157.5) && (longitude < -142.5)) // UTC-10
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+10"); tzName = "Whiskey"; }

else if ((longitude > -142.5) && (longitude < -127.5)) // UTC-9
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+9"); tzName = "Victor"; }

else if ((longitude > -127.5) && (longitude < -112.5)) // UTC-8
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+8"); tzName = "Uniform"; }

else if ((longitude > -112.5) && (longitude < -97.5)) // UTC-7
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+7"); tzName = "Tango"; }

else if ((longitude > -97.5) && (longitude < -82.5)) // UTC-6
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+6"); tzName = "Sierra"; }

else if ((longitude > -82.5) && (longitude < -67.5)) // UTC-5
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+5"); tzName = "Romeo"; }

else if ((longitude > -67.5) && (longitude < -52.5)) // UTC-4
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+4"); tzName = "Quebec"; }

else if ((longitude > -52.5) && (longitude < -37.5)) // UTC-3
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+3"); tzName = "Papa"; }

else if ((longitude > -37.5) && (longitude < -22.5)) // UTC-2
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+2"); tzName = "Oscar"; }

else if ((longitude > -22.5) && (longitude < -7.5)) // UTC-1
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+1"); tzName = "November"; }

else
{    useThisTZ = TimeZone.getTimeZone("Etc/GMT+0"); tzName = "Error"; }

runDate.setTimeZone(useThisTZ);

请注意,这是您提供的代码的翻译,与原始代码保持了相同的逻辑和结构。如果您有任何疑问或需要进一步的帮助,请随时提问。

英文:

Following Ole V.V. guidance this java code chooses and selects the correct time zone.
This code is illustrative not efficient but it works.

            runDate = Calendar.getInstance(); 
// select timezone geographically by longitude
// degrees West = - longitude  0 to -180
// degrees East = + longitude  0 to +180
// the logic below proceeds eastward from Greenwich
if ((longitude &gt; -7.5) &amp;&amp; (longitude &lt; 7.5)) //UTC+0
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+0&quot;); tzName = &quot;Zulu&quot;;       }
else  if ((longitude &gt; 7.5) &amp;&amp; (longitude &lt; 22.5)) //UTC+1
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-1&quot;); tzName = &quot;Alpha&quot;;       }
else  if ((longitude &gt; 22.5) &amp;&amp; (longitude &lt; 37.5)) //UTC+2
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-2&quot;); tzName = &quot;Bravo&quot;;       }
else  if ((longitude &gt; 37.5) &amp;&amp; (longitude &lt; 52.50)) //UTC+3
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-3&quot;); tzName = &quot;Charlie&quot;;     }
else  if ((longitude &gt; 52.5) &amp;&amp; (longitude &lt; 67.5)) //UTC+4
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-4&quot;); tzName = &quot;Delta&quot;;       }
else  if ((longitude &gt; 67.5) &amp;&amp; (longitude  &lt; 82.5)) //UTC+5
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-5&quot;); tzName = &quot;Echo&quot;;        }
else  if ((longitude &gt; 82.5) &amp;&amp; (longitude &lt; 97.5)) //UTC+6
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-6&quot;); tzName = &quot;Foxtrot&quot;;     }
else  if ((longitude &gt; 97.5) &amp;&amp; (longitude &lt; 112.5)) //UTC+7
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-7&quot;); tzName = &quot;Golf&quot;;     }
else  if ((longitude &gt; 112.5) &amp;&amp; (longitude &lt; 127.5)) //UTC+8
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-8&quot;); tzName = &quot;Hotel&quot;;     }
else  if ((longitude &gt; 127.5) &amp;&amp; (longitude &lt; 142.5)) //UTC+9
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-9&quot;); tzName = &quot;India&quot;;     }
else  if ((longitude &gt; 142.5) &amp;&amp; (longitude &lt; 157.5)) //UTC+10
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-10&quot;); tzName = &quot;Kilo&quot;;     }
else  if ((longitude &gt; 157.5) &amp;&amp; (longitude &lt; 172.5)) //UTC+11
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-11&quot;); tzName = &quot;Lima&quot;;     }
else  if ((longitude &gt; 172.5) &amp;&amp; (longitude &lt; 180)) //UTC+12 7.5 degrees wide
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT-12&quot;); tzName = &quot;Mike&quot;;     }
else  if ((longitude &gt; -180) &amp;&amp; (longitude &lt; -172.5)) //UTC-12 7.5 degrees wide
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+12&quot;); tzName = &quot;Yankee&quot;;     }
else  if ((longitude &gt; -172.5) &amp;&amp; (longitude &lt; -157.5)) //UTC-11
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+11&quot;); tzName = &quot;X-Ray&quot;;     }
else  if ((longitude &gt; -157.5) &amp;&amp; (longitude &lt; -142.5)) //UTC-10
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+10&quot;); tzName = &quot;Whiskey&quot;;     }
else  if ((longitude &gt; -142.5) &amp;&amp; (longitude &lt; -127.5)) //UTC-9
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+9&quot;); tzName = &quot;Victor&quot;;     }
else  if ((longitude &gt; -127.5) &amp;&amp; (longitude &lt; -112.5)) //UTC-8
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+8&quot;); tzName = &quot;Uniform&quot;;     }
else  if ((longitude &gt; -112.5) &amp;&amp; (longitude &lt; -97.5)) //UTC-7
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+7&quot;); tzName = &quot;Tango&quot;;     }
else  if ((longitude &gt; -97.5) &amp;&amp; (longitude &lt; -82.5)) //UTC-6
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+6&quot;); tzName = &quot;Sierra&quot;;     }
else  if ((longitude &gt; -82.5) &amp;&amp; (longitude &lt; -67.5)) //UTC-5
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+5&quot;); tzName = &quot;Romeo&quot;;     }
else  if ((longitude &gt; -67.5) &amp;&amp; (longitude &lt; -52.5)) //UTC-4
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+4&quot;); tzName = &quot;Quebec&quot;;     }
else  if ((longitude &gt; -52.5) &amp;&amp; (longitude &lt; -37.5)) //UTC-3
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+3&quot;); tzName = &quot;Papa&quot;;     }
else  if ((longitude &gt; -37.5) &amp;&amp; (longitude &lt; -22.5)) //UTC-2
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+2&quot;); tzName = &quot;Oscar&quot;;     }
else  if ((longitude &gt; -22.5) &amp;&amp; (longitude &lt; -7.5)) //UTC-1
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+1&quot;); tzName = &quot;November&quot;;     }
else
{    useThisTZ = TimeZone.getTimeZone(&quot;Etc/GMT+0&quot;); tzName = &quot;Error&quot;;        }
runDate.setTimeZone(useThisTZ);
</details>

huangapple
  • 本文由 发表于 2020年9月24日 01:50:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/64033628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定