투케이2K

107. (Go Lang) [Mac Os] Go 문법 : time 모듈 - 타임 모듈 사용해 현재 날짜 및 시간 연,월,일,시,분,초 출력 - yyyyMMddHHmmss 본문

Go Lang (Go 언어)

107. (Go Lang) [Mac Os] Go 문법 : time 모듈 - 타임 모듈 사용해 현재 날짜 및 시간 연,월,일,시,분,초 출력 - yyyyMMddHHmmss

투케이2K 2024. 3. 3. 09:35
반응형

[개발 환경 설정]

개발 언어 : Go

 

[소스 코드]

package main

import (
	"fmt"
	"time"
)

// -------------------------------------------------------------------------------

// [기본 서버 구동 함수]
func main() {

	// ---------------------------------------------------
	// [기본 설명]
	// ---------------------------------------------------
	// "time" 패키지를 사용해 기본 현재날짜 및 utc 시간 등을 확인할 수 있습니다
	// ---------------------------------------------------
	// Now : 현재 설정 된 로컬 실시간 시간을 확인합니다
	// ---------------------------------------------------

	// [기본 변수 선언]
	now := time.Now()

	// [현재 날짜 및 시간 포맷 지정 : yyyy-MM-dd HH:mm:ss]
	nowDate := now.Format("2006-01-02 15:04:05")

	// [연,월,일 시:분:초 각각 출력]
	nowYear := now.Year()
	nowMonth := now.Month()
	nowDay := now.Day()

	nowHour := now.Hour()
	nowMinute := now.Minute()
	nowSecond := now.Second()

	// [로그 출력]
	fmt.Println("")
	fmt.Println("----------------------------------------------")
	fmt.Println("[Main] : [Log]")
	fmt.Println("----------------------------------------------")
	fmt.Println("nowDate : ", nowDate)
	fmt.Println("----------------------------------------------")
	fmt.Println("nowYear : ", nowYear)
	fmt.Println("----------------------------------------------")
	fmt.Println("nowMonth : ", nowMonth)
	fmt.Println("----------------------------------------------")
	fmt.Println("nowDay : ", nowDay)
	fmt.Println("----------------------------------------------")
	fmt.Println("nowHour : ", nowHour)
	fmt.Println("----------------------------------------------")
	fmt.Println("nowMinute : ", nowMinute)
	fmt.Println("----------------------------------------------")
	fmt.Println("nowSecond : ", nowSecond)
	fmt.Println("----------------------------------------------")
	fmt.Println("")

}

// -------------------------------------------------------------------------------
 

[결과 출력]


 

반응형
Comments