출처: http://november11tech.tistory.com/88 [Mr.november11] '개발/JAVA' 카테고리의 글 목록 (3 Page) :: 사월은 봄이다.

원래는 long형태를 바꾸려고 했는데 String이 나을 것 같아서...

뭐, 이거나 저거나..ㅎ





      SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmss");

        Date date = new Date();

        try {

date = format2.parse("20170911131533");

} catch (ParseException e) {

e.printStackTrace();

}   

        


// 이 부분은 확인 차...

        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HHmmss");

        String df = format1.format(date);

        System.out.println(df)

'개발 > JAVA' 카테고리의 다른 글

tes  (0) 2018.02.10
시간 차이를 구한다.  (0) 2018.02.10
Set 정렬하기  (0) 2018.02.10
특수문자 제거  (0) 2018.02.10
java8에서 날짜  (0) 2018.02.10

Set은 중복 없이 값을 넣는 녀석이다.


Set<String> eldEventDate = new HashSet<String>();


eldEventDate.add("eld"); // 값을 넣어주고


List <String> a = new ArrayList<>(totalDays);

Collections.sort(a);




이러면 된다.


헷-



'개발 > JAVA' 카테고리의 다른 글

시간 차이를 구한다.  (0) 2018.02.10
String 날짜를 Date로 바꾸기  (0) 2018.02.10
특수문자 제거  (0) 2018.02.10
java8에서 날짜  (0) 2018.02.10
string.format 에서 % 표현법  (0) 2018.02.10
 public static String StringReplace(String str){      
      String match = "[^\uAC00-\uD7A3xfe0-9a-zA-Z\\s]";
      str =str.replaceAll(match, " ");
      return str;
   }


'개발 > JAVA' 카테고리의 다른 글

String 날짜를 Date로 바꾸기  (0) 2018.02.10
Set 정렬하기  (0) 2018.02.10
java8에서 날짜  (0) 2018.02.10
string.format 에서 % 표현법  (0) 2018.02.10
split -> Array List로 집어 넣기  (0) 2018.02.10

좋은 것을 발견했다.


 



간단하게 해결이 된다.



출처 : http://www.w3ii.com/ko/java8/java8_datetime_api.html


'개발 > JAVA' 카테고리의 다른 글

Set 정렬하기  (0) 2018.02.10
특수문자 제거  (0) 2018.02.10
string.format 에서 % 표현법  (0) 2018.02.10
split -> Array List로 집어 넣기  (0) 2018.02.10
int to hex  (0) 2018.02.10

아오, 이놈떄문에 엄청 고생했다.


처음엔, 


String query = String.format("select user_id from hs_driving_log "

+ "where start_date = \'%s\' "

+ "and end_date between \'%s\'and \'%s\'  "

+ "and user_id like \'U_%\'" , startDate , startDate, endDate);



이렇게만 썼는데 자꾸만 [Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '''] 

이런 오류가 났다.



열심히 검색해 본 결과, 


String query = String.format("select user_id from hs_driving_log "

+ "where start_date = \'%s\' "

+ "and end_date between \'%s\'and \'%s\'  "

+ "and user_id like \'U_%%\' " , "20170221" , "20170221", "20170222");

System.out.println("q:" + query);



%의 경우, %% 로 해줘야 알아먹는다.



휴-




'개발 > JAVA' 카테고리의 다른 글

특수문자 제거  (0) 2018.02.10
java8에서 날짜  (0) 2018.02.10
split -> Array List로 집어 넣기  (0) 2018.02.10
int to hex  (0) 2018.02.10
String null 체크  (0) 2018.02.10

String a = "1,2,3" ;

System.out.println(a);

String [] items = a.split(",");

List<String> list = new ArrayList<String>(Arrays.asList(items));

for (String st : list) {

System.out.println(st);

}






이렇게 사용하면 된다.


'개발 > JAVA' 카테고리의 다른 글

java8에서 날짜  (0) 2018.02.10
string.format 에서 % 표현법  (0) 2018.02.10
int to hex  (0) 2018.02.10
String null 체크  (0) 2018.02.10
Unix Time, Local Time  (0) 2018.02.10

흠, Integer에 함수가 있었다.

private String seqIdtoHex(){

int seq = (int) (Math.random() * (65535 - 1 + 1)) + 1;

String result = Integer.toHexString(seq);

return result;

}




 




여기 보면 random으로 돌리는데, random으로 뽑으려는 수가 Min에서 Max 사이의 수를 뽑기 위함이다.


hex로 변환하려면, Integer.toHexString 으로 하면 String 형식으로 반환해준다.



'개발 > JAVA' 카테고리의 다른 글

string.format 에서 % 표현법  (0) 2018.02.10
split -> Array List로 집어 넣기  (0) 2018.02.10
String null 체크  (0) 2018.02.10
Unix Time, Local Time  (0) 2018.02.10
Session attribute 뽑아내기  (0) 2018.02.10
NULL을 체크해 보자.


if (param != null && param.length() != 0) {
    // 값이 있는 경우 처리
} else { 
    // 값이 없는 경우 처리
}

if (param == null || param.length() == 0) {
    // 값이 없는 경우 처리
} else { 
    // 값이 있는 경우 처리
}


param.equal("")을 쓸 경우에, 불필요한 리소스를 사용 하므로(사실 그다지 큰 영향을 끼치지는 않지만.) 기호를 이용해 사용한다.


'개발 > JAVA' 카테고리의 다른 글

split -> Array List로 집어 넣기  (0) 2018.02.10
int to hex  (0) 2018.02.10
Unix Time, Local Time  (0) 2018.02.10
Session attribute 뽑아내기  (0) 2018.02.10
Map의 Key 값 확인하기  (0) 2018.02.10

보통은, JVM time zone을 따라간다.


하지만, 나는 글로벌하게, Unix Time을 가져와주지!




private long timeline(){

long time = System.currentTimeMillis();

TimeZone tz = TimeZone.getDefault();

int offset = tz.getOffset(time);

long now = time - offset ;

        return now ;

}



이렇게 해주면 unix time을 가지고 온다.


이걸 timezone을 이용해 원하는 local time으로 수정


private String timeZoneTime(long unixTime, String timezone,String timeFormat){

Calendar  cal  =  Calendar.getInstance();

        String today = CommonUtils.DateSecondsFormater.format(unixTime); 

        String timeline = DateUtils.getLocaTime(today,CommonUtils.longTypeFormaterString, timezone, timeFormat);

        

        return timeline;

}








'개발 > JAVA' 카테고리의 다른 글

int to hex  (0) 2018.02.10
String null 체크  (0) 2018.02.10
Session attribute 뽑아내기  (0) 2018.02.10
Map의 Key 값 확인하기  (0) 2018.02.10
시간  (0) 2018.02.10

Enumeration se = session.getAttributeNames();

while(se.hasMoreElements()){

String getse = se.nextElement().toString();

System.out.println("getse:" + getse);

if(getse.equals("tabNum")){

String tabNum = (String)session.getAttribute("tabNum");

if(StringUtils.isNotEmpty(tabNum)){

mav.addObject("tabNum", tabNum);

session.setAttribute("tabNum", 0);

System.out.println("session tabNum : " + session.getAttribute("tabNum"));

}

break;

}

}

'개발 > JAVA' 카테고리의 다른 글

String null 체크  (0) 2018.02.10
Unix Time, Local Time  (0) 2018.02.10
Map의 Key 값 확인하기  (0) 2018.02.10
시간  (0) 2018.02.10
xml 만들어서 저장하기  (0) 2018.02.10

+ Recent posts