Java String to Timestamp getTimestamp(String timezone, String dateTime, String pattern)

Here you can find the source of getTimestamp(String timezone, String dateTime, String pattern)

Description

get Timestamp

License

Apache License

Declaration

public static long getTimestamp(String timezone, String dateTime, String pattern) throws ParseException 

Method Source Code


//package com.java2s;
/*//from  w ww.j  a  va2  s .c  o m
 * Commons-Utils
 * Copyright (c) 2017.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.TimeZone;

public class Main {
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    public static long getTimestamp(String timezone, String dateTime, String pattern) throws ParseException {
        SimpleDateFormat sdf = null;
        if (null == pattern || "".equals(pattern)) {
            sdf = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
        } else {
            sdf = new SimpleDateFormat(pattern);
        }
        sdf.setTimeZone(TimeZone.getTimeZone(timezone));
        long b = sdf.parse(dateTime).getTime() / 1000;
        return b;
    }
}

Related

  1. getTimestamp(String dateValue, String pattern, TimeZone timezone)
  2. getTimestamp(String pattern)
  3. getTimeStamp(String pattern, String strDate)
  4. getTimeStamp(String style, Date date)
  5. getTimestamp(String timeStampStr, String logRundateIdStr)
  6. getTimestampFromDateString(String date)
  7. getTimeStampInSecond(String timeStr)
  8. isTimestamp(String str, boolean allowEmpty)
  9. isTimeStampValid(String timestamp)