JAVA编程训练——Current date and time

       Invoking System.currentTimeMillis() returns the elapase time in milliseconds since midnight of January 1, 1970. Write a program that displays the date and time.


直接上强制类型转换

import java.util.Date;
import java.util.Scanner;
import java.util.Calendar;
public class Hello
{
	public static void main(String[] args)
	{
		String m[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
		int year,month,day,hour,minute,second;
		long currentTime = System.currentTimeMillis();
		Date date =new Date(currentTime);
		year=date.getYear()+1900;
		month=date.getMonth();
		day=date.getDate();
		hour=date.getHours();
		minute=date.getMinutes();
		second=date.getSeconds();
		System.out.print("Current date and time is "+m[month]);
		System.out.println(" "+day+", "+year+" "+hour+":"+minute+":"+second);
	}
}


### 回答1: 好的,您可以按照以下步骤修改.profile文件实现您的需求: 1. 打开终端 2. 输入以下命令编辑.profile文件: nano ~/.profile 3. 在打开的文件中,将光标移至末尾添加以下两行代码: echo "Hello World" echo "Current Date and Time: $(date)" 4. 按下"Ctrl + O"保存文件,按下"Ctrl + X"退出编辑器 5. 在终端中输入以下命令以让修改生效: source ~/.profile 这样每次登录时,终端都会显示"Hello World"和当前日期时间。 ### 回答2: 要修改.profile文件以便每次登录时显示"Hello World Current Date and Time: [The current date and time]" 的信息,可以按照以下步骤进行: 1. 打开终端并登录到系统。 2. 使用任何文本编辑器(例如vi、nano等),打开.profile文件: ``` vi ~/.profile ``` 3. 进入编辑模式,在文件最后添加以下内容: ``` echo "Hello World Current Date and Time: $(date +%Y-%m-%d\ %H:%M:%S)" ``` 这个命令会显示"Hello World Current Date and Time:",后面跟着当前的日期和时间,日期和时间将以"YYYY-MM-DD HH:MM:SS"的格式显示。%Y代表年份,%m代表月份,%d代表日期,%H代表小时,%M代表分钟,%S代表秒钟。使用$(date command)获取当前日期和时间的值。 4. 保存文件并关闭编辑器。 5. 每次重新登录时,.profile文件将会执行其中的命令并显示信息"Hello World Current Date and Time: [The current date and time]",其中的[date and time]将会被当前日期和时间的值所替代。 完成上述步骤后,你每次登录时都将会看到你所期望的信息。记得在保存文件后,重新启动一个终端来查看结果。 ### 回答3: 首先,打开终端并输入以下命令,以编辑.profile文件: ```bash vi ~/.profile ``` 然后按下字母键盘的"i"键,进入编辑模式。 在文件的末尾添加以下行: ```bash echo "Hello World Current Date and Time: $(date +'%Y-%m-%d %H:%M:%S')" ``` 按下"Esc"键退出编辑模式。 输入以下命令保存并关闭文件: ```bash :wq ``` 此时,您的.profile文件已修改成功。 重新启动终端,或者输入以下命令以使修改生效: ```bash source ~/.profile ``` 每次您登录时,终端将显示"Hello World Current Date and Time: [The current date and time]"信息,其中"[The current date and time]"将被替换为实际的当前日期和时间。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值