package com.ruoyi.platform.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateUtils {

    public static Date convertUTCtoShanghaiDate(String utcTime) throws ParseException {

        // Create a SimpleDateFormat object with the UTC date format
        SimpleDateFormat utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

        // Parse the UTC time string into a Date object
        Date utcDate = utcFormatter.parse(utcTime);

        // Create a SimpleDateFormat object with the Shanghai date format
        SimpleDateFormat shanghaiFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        shanghaiFormatter.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));

        // Format the UTC Date object in Shanghai time
        String shanghaiTime = shanghaiFormatter.format(utcDate);

        // Parse the Shanghai time string into a Date object
        Date shanghaiDate = shanghaiFormatter.parse(shanghaiTime);

        // Return the Shanghai Date object
        return shanghaiDate;
    }

}
