小编Jua*_*oya的帖子

将时区更改为伦敦时的日期问题

我有以下代码:

package com.company.customer;

import java.util.*;
import java.text.*;
import java.io.*;

public class DateSample {
    private TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
    private SimpleDateFormat sdfDate = new SimpleDateFormat();
    private Date inputDate;
    private String dateInString = "2015-07-15";
    private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

    public void datePrint() {
        sdfDate.setTimeZone(GMT_TIMEZONE);
        sdfDate.applyPattern("EE-ddMMM");

        try {
            inputDate = formatter.parse(dateInString);
        } catch (Exception e) {
            System.out.println("populateTabDates: ParseException");
        }

        String formatResults = sdfDate.format(inputDate);

        // Modify the return to cut down the weekday: Fri-20Aug => Fr-20Aug
        formatResults = formatResults.substring(0, 2) + formatResults.substring(3);

        System.out.println(formatResults); …
Run Code Online (Sandbox Code Playgroud)

java date

2
推荐指数
1
解决办法
75
查看次数

标签 统计

date ×1

java ×1