⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isodate.java

📁 Mofire的JAR压缩包
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   IsoDate.java

package org.kobjects.isodate;

import java.util.*;

public class IsoDate
{

	public static final int DATE = 1;
	public static final int TIME = 2;
	public static final int DATE_TIME = 3;

	public IsoDate()
	{
	}

	static void dd(StringBuffer buf, int i)
	{
		buf.append((char)(48 + i / 10));
		buf.append((char)(48 + i % 10));
	}

	public static String dateToString(Date date, int type)
	{
		Calendar c = Calendar.getInstance();
		c.setTimeZone(TimeZone.getTimeZone("GMT"));
		c.setTime(date);
		StringBuffer buf = new StringBuffer();
		if ((type & 1) != 0)
		{
			int year = c.get(1);
			dd(buf, year / 100);
			dd(buf, year % 100);
			buf.append('-');
			dd(buf, (c.get(2) - 0) + 1);
			buf.append('-');
			dd(buf, c.get(5));
			if (type == 3)
				buf.append("T");
		}
		if ((type & 2) != 0)
		{
			dd(buf, c.get(11));
			buf.append(':');
			dd(buf, c.get(12));
			buf.append(':');
			dd(buf, c.get(13));
			buf.append('.');
			int ms = c.get(14);
			buf.append((char)(48 + ms / 100));
			dd(buf, ms % 100);
			buf.append('Z');
		}
		return buf.toString();
	}

	public static Date stringToDate(String text, int type)
	{
		Calendar c = Calendar.getInstance();
		if (type != 3)
			c.setTime(new Date(0L));
		if ((type & 1) != 0)
		{
			c.set(1, Integer.parseInt(text.substring(0, 4)));
			c.set(2, (Integer.parseInt(text.substring(5, 7)) - 1) + 0);
			c.set(5, Integer.parseInt(text.substring(8, 10)));
			if (type == 3)
				text = text.substring(11);
		}
		if ((type & 2) == 0)
			return c.getTime();
		c.set(11, Integer.parseInt(text.substring(0, 2)));
		c.set(12, Integer.parseInt(text.substring(3, 5)));
		c.set(13, Integer.parseInt(text.substring(6, 8)));
		int pos = 8;
		if (pos < text.length() && text.charAt(pos) == '.')
		{
			int ms = 0;
			int f = 100;
			do
			{
				char d = text.charAt(++pos);
				if (d < '0' || d > '9')
					break;
				ms += (d - 48) * f;
				f /= 10;
			} while (true);
			c.set(14, ms);
		} else
		{
			c.set(14, 0);
		}
		if (pos >= text.length())
			return c.getTime();
		if (text.charAt(pos) == '+' || text.charAt(pos) == '-')
		{
			c.setTimeZone(TimeZone.getTimeZone("GMT"));
			return new Date(c.getTime().getTime() + (long)((Integer.parseInt(text.substring(pos + 1, pos + 3)) * 60 + Integer.parseInt(text.substring(pos + 4, pos + 6))) * (text.charAt(pos) != '-' ? 60000 : -60000)));
		}
		if (text.charAt(pos) == 'Z')
		{
			c.setTimeZone(TimeZone.getTimeZone("GMT"));
			return c.getTime();
		} else
		{
			throw new RuntimeException("illegal time format!");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -