All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hibegin.common.util.DateUtils Maven / Gradle / Ivy

Go to download

Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project. Can quickly run embedded, Android devices

There is a newer version: 0.3.162
Show newest version
package com.hibegin.common.util;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateUtils {

    public static String toGMTString(Date date){
        Instant instant = date.toInstant();
        // 将Instant转换为ZonedDateTime,指定GMT时区
        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of("GMT"));
        // 创建一个DateTimeFormatter并指定为Cookie过期日期的格式
        DateTimeFormatter cookieExpireFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'", java.util.Locale.ENGLISH);
        // 使用DateTimeFormatter格式化日期时间为Cookie的过期日期格式
        return zonedDateTime.format(cookieExpireFormatter);
    }

    public static void main(String[] args) {
        String gmt = toGMTString(new Date());
        System.out.println("gmt = " + gmt);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy