Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import java.util.Locale;

public class Main {
    public static String getYesterdayFormattedTime() {

        Calendar calendar = getCurrentCalendar();
        calendar.add(Calendar.HOUR_OF_DAY, -9);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
        String result = format.format(calendar.getTime());
        String standardName = "";
        if (result.contains("JST")) {
            standardName = "JST";
            result = result.replaceAll(standardName, "+09:00");
        } else if (result.contains("GMT")) {
            standardName = "GMT";
            result = result.replaceAll(standardName, "");
        }
        return result;
    }

    public static Calendar getCurrentCalendar() {

        Calendar currentCal = new GregorianCalendar(Locale.JAPAN);

        return currentCal;
    }
}