栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA小实例(十四)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA小实例(十四)

本次的实例是实现BJT转换为UTC(一个时间转换)

代码如下:

package test02;

import java.util.Scanner;

public class TimeT 
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		System.out.println("请输入BJT小时");
		int BJTH = in.nextInt();
		System.out.println("请输入BJT分钟");
		int BJTM = in.nextInt();
		
		String h = BJTH + "";
		String m = BJTM + ""; ;
		String BJT = h + m;
		
	if(BJTH<=23&&BJTM<=59)
	{
		if(BJTH<10)
		{
			if(BJTH==0)
		 {
				if(BJTM>=10)
				{   
					int h1 = Integer.parseInt(BJT)/100;
					int m1 = Integer.parseInt(BJT)%100;
					int h2 = h1 - 8;
					if(h2<0){
						 
						h2 +=24;
					}
					int UTC=h2*100+m1;

					System.out.println("UTC为"+UTC);
				}else
				{
					int h3 = Integer.parseInt(BJT)/100;
					int m2 = Integer.parseInt(BJT)%100;
					int h4 = h3 - 8;
					if(h4<0){
						 
						h4 +=24;
					}
					int UTC=h4*100+m2;
					System.out.println("UTC为"+UTC);
					
				}
		 }else
		 {
			if(BJTM>=10)
			{
				int h5 = Integer.parseInt(BJT)/100;
				int m3 = Integer.parseInt(BJT)%100;
				int h6 = h5 - 8;
				if(h6<0){
					 
					h6 +=24;
				}
				int UTC=h6*100+m3;

				System.out.println("UTC为"+UTC);
			}else
			{
				BJT = h+"0"+m;
				int h7 = Integer.parseInt(BJT)/100;
				int m4 = Integer.parseInt(BJT)%100;
				int h8 = h7 - 8;
				if(h8<0){
					 
					h8 +=24;
				}
				int UTC=h8*100+m4;

				System.out.println("UTC为"+UTC);

			}
		 }
		 
		
		}else
		{
			if(BJTM>=10)
			{
				int h9 = Integer.parseInt(BJT)/100;
			    int m5 = Integer.parseInt(BJT)%100;
			    int h10 = h9 - 8;
			    if(h10<0){
				 
				h10 +=24;
			}
			int UTC=h10*100+m5;

			System.out.println("UTC为"+UTC);
				
			}else
			{
				BJT = h + "0" + m;
				int h11 = Integer.parseInt(BJT)/100;
				int m6 = Integer.parseInt(BJT)%100;
				int h12 = h11 - 8;
				if(h12<0){
					h12 +=24;
				}
				int UTC=h12*100+m6;

				System.out.println("UTC为"+UTC);
			}
		}
	}else
	{
		System.out.println("输入数字不合法,请重新输入!");
	}	
		
	}
	
}

注:代码可能有些冗余,但功能没问题,后面会改进的。

欢迎有想法的小伙伴来交流探讨!

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/489917.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号