跳至主要内容

java 날짜,시간 출력

SimpleDateFormat

  • 출력형식의 패턴을 작성하여 SimpleDateFormat인스턴스를 생성
  • format(Date d)메서드 호출하여 지정한 형식의 문자열을 얻음
Date today = new Date();
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(outFormat.format(today));


기호  의미 보기
G 연대(BC, AD) AD
y 년도 1996; 2019
M 월(1~12 또는 1월~12) 3;3월;12;12월
w 년의 몇번째 주(1~53) 50
W 월의 몇번째 주(1~5) 300
D 년의 몇번째 일(1~366) 20
d 월의 몇번째 일(1~31) 10
F 월의 몇번째 요일(1~5) 5
E 요일
a 오전/오후 AM;PM
H 시간(0~23) 20
k 시간(1~24) 24
K 시간(0~11) 11
h 시간(1~12) 12
m 분(0~59) 30
s 초(0~59) 55
S 천분의 일초(0~999) 978
z General time zone GMT-08:00
Z RFC 822 time zone +0900
X ISO 8601 time zone -08-0800-08:00
' escape문자 특수문자를 표현하는데 사용

날짜 출력형식 변환

parse(String source)를 사용하여 문자열 source를 날짜 Date인스턴스로 변환함.
DateFormat inFormat = new SimpleDateFormat("yyyy년MM월dd일");
DateFormat outFormat = new SimpleDateFormat("yyyy/MM/dd");

try{
Date hour = inFormat.parse("2017년12월25일");
System.out.println(outFormat.format(hour));
}catch(ParseException e){
e.printStackTrace();
}
output >> 2017/12/25

评论

此博客中的热门博文

Pandas Plot

pandas.DataFrame.plot.bar import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(5, 4).round(1),                   index=['snail', 'pig', 'elephant','rabbit', 'giraffe'],                   columns=pd.Index(['speed', 'lifespan', 'active', 'cuite'],                   name='Genus')) ax = df.plot(kind='bar',figsize=(10,4), rot = 0) plt.show() ==> output in Pycharm

TensorFlow

Anaconda를 이용하여 Tensorflow 설치 Conda환경을 생성 #conda create -n 가상환경 이름 conda create -n tf python=3.6 anaconda 설치된 가상환경 실행 activate tf tf 가상환경에서 tensorflow 설치 pip install tensorflow      TensorFlow 개요 TensorFlow는 dataflow graph로 수학 계산과 데이터의 흐름을 나타낸다. TensorFlow는 dataflow graph를 구성 한 후 session을 생성하여 graph의 일부를 실행한다 Computation Graph TensorFlow 프로그램은 구성 단계 와 실행 단계 로 구성 구성(construction) 단계: 그래프를 조립 실행(execution) 단계: Session을 통해 그래프 연산을 실행 TensorFlow 기본적인 사용법 Argmax 설정한 axis에 따른 가장 큰 값을 가지는 요소의 index를 반환 axis = 0일때 x[0]와 x[1]의 각 요소들을 비교하여 큰 수의 index를 반환하고, axis = 1일때 x[0][]의 요소들 내 큰 수의 index와 x[1][]의 요소들 내 가장 큰 수의 index를 반환 Reshape tf.reshape(tensor, shape, name = None) tensor의 구조를 원하는 shape으로 변환 shape의 한 원소가 -1이라면, 전체 크기가 일정하게 유지되도록 해당 차원의 길이가 자동으로 계산된다. squeeze 차원 중 크기가 1인 차원을 스칼라값으로 바꿔 해당 차원을 제거한다. TensorBoard TensorBard는 TensorFlow에 기록된 로그를 그래프로 시각화시켜 보여주는 도구이다. TensorBoard 실행 tf.summary.FileWriter('log_dir', graph ...