[flutter] 플러터에서 현재 연도와 월 가져오기
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
DateTime now = DateTime.now();
int year = now.year;
int month = now.month;
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Current Date'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Year: $year',
),
Text(
'Month: $month',
),
],
),
),
),
);
}
}
이 예제에서는 DateTime.now()
를 사용하여 현재 날짜와 시간을 얻어온 후, 해당 값을 이용하여 현재 연도와 월을 가져왔습니다.
참고 자료:
- Flutter 공식 문서: https://flutter.dev/docs
- Dart 공식 문서: https://dart.dev/guides
언제든지 더 궁금한 점이 있으시면 물어보세요!