三星题:(Current date and time)
2015-10-20 17:44
253 查看
问题及代码: public class Get_the_data { public static void main(String[] args) { int year = 1970, month = 1, days, hours, minutes; long Get_second = (long) (System.currentTimeMillis() / 1000); //取出0区的时间 // 一般的 年 月 日的时间 int Year_sec = 365 * 24 * 60 * 60; int[] Month_day = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int Day_sec = 24 * 60 * 60; int Hour_sec = 60 * 60; int Minute_sec = 60; while (Get_second >= Year_sec) // 算出年数 { year++; Get_second -= Year_sec; if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { Get_second -= Day_sec; } } if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) // 确定现在是否是闰年 Month_day[2] = 29; int i = 1; while (Get_second >= Day_sec * Month_day[i]) // 算出月份 { month++; Get_second -= Day_sec * Month_day[i]; i++; } String Months; switch (month) { case 1: Months = "January"; break; case 2: Months = "February"; break; case 3: Months = "March"; break; case 4: Months = "April"; break; case 5: Months = "May"; break; case 6: Months = "June"; break; case 7: Months = "Jule"; break; case 8: Months = "August"; break; case 9: Months = "September"; break; case 10: Months = "October"; break; case 11: Months = "November"; break; case 12: Months = "December"; break; default: Months = "Error!"; break; } days = (int) (Get_second / Day_sec + 1); // 确定现在的天 Get_second %= Day_sec; hours = (int) (Get_second / Hour_sec+8); // 确定现在的小时(北京时间) Get_second %= Hour_sec; minutes = (int) (Get_second / Minute_sec); // 确定日期的分钟 Get_second %= Minute_sec; // 确定日期的秒数 System.out.print("Current date and time is " + Months + " " + days + ", " + year + " " + hours + ":" + minutes + ":" + Get_second); } } 运行结果:
相关文章推荐
- MFC 模态及非模态对话框
- 并查集应用 —— POJ 1182 食物链
- 结构型模式之五——享元模式
- asp.net mvc HandleErrorAttribute 异常错误处理 无效!
- Android WebView常见问题及解决方案汇总
- 网站上通过nginx部署ssl证书
- 谷歌应用市场4
- 物联网协议比较 MQTT CoAP RESTful/HTTP XMPP
- Android 常见命令操作(需要配置adb.exe的环境变量)
- 常用JS
- Linux下profile environment bashrc的区别
- 《转》IEnumerable、IEnumerator两个接口的认识
- Map Wiki -- proposed by Shuo Ren
- 实现windows批处理下的计时功能
- 【转】mac上安装gradle
- [算法练习]最长公共子序列
- 使用Git的Push出现rejected - non-fast-forward错误
- iOS开发笔记--iOS应用架构谈 view层的组织和调用方案
- MySQL编码问题
- 关于bundle的创建方式