java时间格式化英文年月,java 日期格式化为年月日时分秒

发布时间:2022-11-29

本文目录一览:

  1. JAVA 中获取时间怎么格式化?
  2. java如何把英文的日期格式改成数字化的
  3. java怎么把时间转换成"12thDecember2012,Wednesday12:12'这种形式
  4. java将英文的日期格式转中文
  5. java如何实现各国时间格式转换成yyyy-mm-dd-hhmmss时间格式?
  6. 在java中如何将数字的日期转换成英文日期?如 01/30转换至january thirtieth.

JAVA 中获取时间怎么格式化?

时间格式化输出主要有两种方式,代码如下:

// 使用Calendar
Calendar now = Calendar.getInstance();
System.out.println("年:" + now.get(Calendar.YEAR));
System.out.println("月:" + (now.get(Calendar.MONTH) + 1));
System.out.println("日:" + now.get(Calendar.DAY_OF_MONTH));
System.out.println("时:" + now.get(Calendar.HOUR_OF_DAY));
System.out.println("分:" + now.get(Calendar.MINUTE));
System.out.println("秒:" + now.get(Calendar.SECOND));
// 使用Date
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("当前时间:" + sdf.format(d));

扩展资料

JAVA中获取当前系统时间。

import java.util.Date;
import java.text.SimpleDateFormat;
public class NowString {
    public static void main(String[] args) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 设置日期格式
        System.out.println(df.format(new Date())); // new Date()为获取当前系统时间
    }
}

参考资料来源:百度百科:Java

java如何把英文的日期格式改成数字化的

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s = sdf.format(date); // 这里的date是你获取到的Wed Nov 30 04:17:15 CST 2011
System.out.println(s); // 打印xxxx-xx-xx xx:xx:xx

java怎么把时间转换成"12thDecember2012,Wednesday12:12'这种形式

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
 * 项目名称:Test
 * 类名称:Empty
 * 类描述:
 * 创建人:Zhou2003737
 * 创建时间:2013-7-23 下午04:42:14
 */
public class Empty {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Date d = new Date();
        // 首先按照d(日)格式化获取日期。
        SimpleDateFormat format = new SimpleDateFormat("d");
        String temp = format.format(d);
        // 判断日期如果为1结尾且不是11则 用"dd'st'MMMMyyyy,EEEEHH:mm, yyyy"格式,设置语言环境为英语。其它类似。
        if (temp.endsWith("1") && !temp.endsWith("11")) {
            format = new SimpleDateFormat("dd'st'MMMMyyyy,EEEEHH:mm, yyyy", Locale.ENGLISH);
        } else if (temp.endsWith("2") && !temp.endsWith("12")) {
            format = new SimpleDateFormat("dd'nd'MMMMyyyy,EEEEHH:mm,yyyy", Locale.ENGLISH);
        } else if (temp.endsWith("3") && !temp.endsWith("13")) {
            format = new SimpleDateFormat("dd'rd'MMMMyyyy,EEEEHH:mm,yyyy", Locale.ENGLISH);
        } else {
            format = new SimpleDateFormat("dd'th'MMMMyyyy,EEEEHH:mm,yyyy", Locale.ENGLISH);
        }
        String result = format.format(d);
        System.out.println(result);
    }
}

刚写的,测试通过。

java将英文的日期格式转中文

实现思路:通过DateFormat函数,之后定义估计的时间日期格式,之后直接输出想要的时间格式即可:

DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
System.out.println("当前的时间是:" + df.format(new Date()));

结果:2015年11月04日 14时24分30秒。

java如何实现各国时间格式转换成yyyy-MM-dd HH:mm:ss时间格式?

SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
Date d = new Date();
String timeStr = sdf1.format(d); // 结果就是这种格式:2014-08-08 08:08:20
String timeStr2 = sdf2.format(d); // 结果就是这种格式:2014年08月08日 08时08分20秒

在java中如何将数字的日期转换成英文日期?如 01/30转换至January thirtieth.

DateFormat df1 = new SimpleDateFormat("MMM-dd'th', yyyy", Locale.ENGLISH);

可以用这个格式化;

Date d = new Date();
d.toGMTString();

Java中DatetoGMTString(格林威治时间)已经不推荐使用

SimpleDateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z", Locale.UK);
df.setTimeZone(new java.util.SimpleTimeZone(0, "GMT"));
return df.format(date);

效果是一样的