本文整理汇总了Java中java.sql.Date.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java Date.valueOf方法的具体用法?Java Date.valueOf怎么用?Java Date.valueOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Date
的用法示例。
在下文中一共展示了Date.valueOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stringToDate
import java.sql.Date; //导入方法依赖的package包/类
public static Date stringToDate(String str, String pattern) {
Date date = null;
try {
date = Date.valueOf(str);
} catch (Exception e) {
throw new IllegalArgumentException("'" + str + "' is not a valid date of pattern '" + pattern + "'", e);
}
return date;
}
示例2: test00
import java.sql.Date; //导入方法依赖的package包/类
@Test(dataProvider = "validDateValues")
public void test00(String d, String expectedD) {
Date d1 = Date.valueOf(d);
Date d2 = Date.valueOf(expectedD);
assertTrue(d1.equals(d2) && d2.equals(d1)
&& d1.toString().equals(expectedD), "Error d1 != d2");
}
示例3: getBirthday
import java.sql.Date; //导入方法依赖的package包/类
/**
* Gets birthday from contacts database cursor object
* @param c cursor for the contact
* @return birthday or null, if birthday column is empty or
* the value can't be parsed into valid date object
*/
private Date getBirthday(Cursor c) {
try {
int colBirthday = c.getColumnIndexOrThrow(CommonDataKinds.Event.START_DATE);
return Date.valueOf(c.getString(colBirthday));
} catch (IllegalArgumentException e) {
LOG.e(LOG_TAG, "Failed to get birthday for contact from cursor", e);
return null;
}
}
示例4: tableChanged
import java.sql.Date; //导入方法依赖的package包/类
public void tableChanged(TableModelEvent e) {
int row=e.getFirstRow();
int userId=Integer.parseInt(table.getValueAt(row, 0).toString());
String userName=table.getValueAt(row, 1).toString();
String pwdString=table.getValueAt(row, 2).toString();
//String IP=table.getValueAt(row, 3).toString();
//String state=table.getValueAt(row, 4).toString();
String userGender=table.getValueAt(row, 5).toString();
String userEmail=table.getValueAt(row, 6).toString();
//String userSignature=table.getValueAt(row, 5).toString();
Date userBirthday=Date.valueOf(table.getValueAt(row, 9).toString());
Users user=new Users(userId,userName,pwdString, userGender, userEmail,userBirthday);
UserDao userDao=new UserDao();
try {
if(userDao.update(user))
{
JOptionPane.showMessageDialog(null, "修改成功!");
}
else {
JOptionPane.showMessageDialog(null, "修改失败!");
}
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
示例5: getD
import java.sql.Date; //导入方法依赖的package包/类
public Date getD(String key) {
if (this == null) {
return null;
}
String output = get(key);
if (output == null || output.equals("")) {
return null;
}
try {
return Date.valueOf(output);
} catch (Exception e) {
return null;
}
}
示例6: getPredicateForDate
import java.sql.Date; //导入方法依赖的package包/类
/**
* Get the correct predicate for Date objects.
*
* @param op the specified predicate operation
* @param initialValue the initial value, to be checked against, for the predicate
* @return the predicate with correct operation and specified initial value
*/
public static Predicate getPredicateForDate(final TypePredicateOp op, final Object initialValue) {
Predicate predicate = null;
Date dateValue = initialValue instanceof Date ? (Date) initialValue
: Date.valueOf(String.valueOf(initialValue));
switch ((CompareOp) op) {
case LESS:
predicate = isLessThan(dateValue);
break;
case LESS_OR_EQUAL:
predicate = isLessThanOrEqual(dateValue);
break;
case GREATER:
predicate = isGreaterThan(dateValue);
break;
case GREATER_OR_EQUAL:
predicate = isGreaterThanOrEqual(dateValue);
break;
case EQUAL:
predicate = isEqual(dateValue);
break;
case NOT_EQUAL:
predicate = isNotEqual(dateValue);
break;
}
return predicate;
}
示例7: test01
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test01() {
Date d = Date.valueOf("1961-08-30");
assertFalse(d.after(d), "Error d.after(d) = true");
}
示例8: test
import java.sql.Date; //导入方法依赖的package包/类
@Test(dataProvider = "invalidDateValues",
expectedExceptions = IllegalArgumentException.class)
public void test(String d) throws Exception {
Date.valueOf(d);
}
示例9: deserialize
import java.sql.Date; //导入方法依赖的package包/类
@Override
public Date deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
return json == null ? null : Date.valueOf(json.getAsString());
}
示例10: test2
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test2() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(System.currentTimeMillis());
assertTrue(d2.after(d), "Error d2.after(d) = false");
}
示例11: test9
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test9() {
Date d = Date.valueOf("1961-08-30");
assertTrue(d.compareTo(d) == 0, "Error d.compareTo(d) !=0");
}
示例12: test21
import java.sql.Date; //导入方法依赖的package包/类
@Test(expectedExceptions = IllegalArgumentException.class)
public void test21() throws Exception {
Date d = Date.valueOf("1961-08-30");
d.getHours();
}
示例13: test17
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test17() {
Date d = Date.valueOf("1961-08-30");
Date d2 = Date.valueOf(d.toString());
assertTrue(d.equals(d2) && d2.equals(d), "Error d != d2");
}
示例14: toDate
import java.sql.Date; //导入方法依赖的package包/类
private static Date toDate(Object x) {
if (x instanceof String) {
return Date.valueOf((String) x);
}
return new Date(toLong(x));
}
示例15: test6
import java.sql.Date; //导入方法依赖的package包/类
@Test
public void test6() {
Date d = Date.valueOf("1961-08-30");
Date d2 = new Date(System.currentTimeMillis());
assertTrue(d.before(d2), "Error d.before(d2) = false");
}