Java SQL Time Create getTimesByStr(String dataStr)

Here you can find the source of getTimesByStr(String dataStr)

Description

get Times By Str

License

Open Source License

Declaration

public static Timestamp getTimesByStr(String dataStr) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;
import java.text.DateFormat;

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

public class Main {

    public static Timestamp getTimesByStr(String dataStr) {
        Date d = getDate(dataStr);
        String newTime = getString2(d);
        return Timestamp.valueOf(newTime);

    }//from ww w. ja v  a2  s.  c o m

    public static Date getDate(String str) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = dateFormat.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return date;
    }

    public static String getDate(int num) {
        Calendar cal = Calendar.getInstance();

        cal.add(Calendar.DAY_OF_MONTH, -num + 1);
        Date date = new Date(cal.getTimeInMillis());
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String str = df.format(date);
        return str;
    }

    public static String getString2(Date date) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String newStr = dateFormat.format(date);

        return newStr;
    }
}

Related

  1. getTimeFormat()
  2. getTimeFromCalendar(final Calendar calendar)
  3. getTimeList(ResultSet resultSet, String columnName)
  4. getTimeLong(ResultSet resultSet)
  5. getTimeNumberFromSqlTime(Time time)
  6. getTimeStr(Time time)
  7. getTimeZone(String id)
  8. getTimeZone(String timezone, String time, DateFormat format)
  9. getTodayAndTime()