All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mtons.utils.AstroUtils Maven / Gradle / Ivy

/*
+--------------------------------------------------------------------------
|   mtons [#RELEASE_VERSION#]
|   ========================================
|   Copyright (c) 2014, 2015 mtons. All Rights Reserved
|   http://www.mtons.com
|
+---------------------------------------------------------------------------
*/
package mtons.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * 星座计算
 * 
 * @author langhsu
 *
 */
public class AstroUtils {
	private static String[] astros = new String[] { "摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座" };
	private static int[] days = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 }; 
	
	public static String star(Date time) {
		if (time == null) {
			return "";
		}
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(time);
		
		int month = calendar.get(Calendar.MONTH) + 1;
		int day = calendar.get(Calendar.DATE);
		
		return star(month, day);
	}
	
	public static String star(int month, int day) {
		return day < days[month - 1] ? astros[month - 1] : astros[month]; 
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy