package com.company;
import java.time.DayOfWeek;
import java.time.LocalDate;
public class Main {
public static void main(String[] args) {
LocalDate date = LocalDate.now();
int month = date.getMonthValue();//获得当前的月
int today = date.getDayOfMonth();//获得当前的日
date = date.minusDays(today - 1);//设置日期为当月的第一天
DayOfWeek weekday = date.getDayOfWeek();//获得日期是星期几
int value = weekday.getValue();//获得星期几的数值
System.out.println("Mon Tue Wed Thu Fri Sat Sun");
for (int i = 1; i < value; i++) {
System.out.print(" ");
}
while (date.getMonthValue() == month) {
System.out.printf("%3d", date.getDayOfMonth());
if (date.getDayOfMonth() == today)
System.out.print("*");
else
System.out.print(" ");
date = date.plusDays(1);
if (date.getDayOfWeek().getValue() == 1)
System.out.println();
}
}
}
using System;
namespace CalendarTest
{
class Program
{
static void Main(string[] args)
{
var date = DateTime.Now;
int month = date.Month;
int today = date.Day;
date = date.AddDays(-today + 1);
var weekday = date.DayOfWeek;
int value = (int)weekday;
Console.WriteLine(" Mon Tue Wed Thu Fri Sat Sun");
for (int i = 1; i < value; i++)
Console.Write("{0,4}","");
while (date.Month==month)
{
Console.Write("{0,4}", date.Day);
if(date.Day==today)
Console.Write("*");
else
Console.Write("");
date = date.AddDays(1);
if((int)date.DayOfWeek==1)
Console.WriteLine();
}
}
}
}