<dependencies> ... <dependency> <groupId>com.github.drapostolos</groupId> <artifactId>moment</artifactId> <version>1.8.0</version> </dependency> ... </dependencies> import com.github.drapostolos.typeparser.TypeParser; import com.github.drapostolos.typeparser.TypeParserException; import com.github.drapostolos.typeparser.TypeParserProxy; import net.sf.junidecode.Junidecode; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import java.text.ParseException; import java.util.Date; public class MomentExample { public static void main(String[] args) throws ParseException { Moment now = Moment.now(); System.out.println(now.format("YYYY-MM-dd HH:mm:ss")); Moment tomorrow = now.add(1, TimeUnit.DAYS); System.out.println(tomorrow.format("YYYY-MM-dd")); boolean isBefore = now.isBefore(tomorrow); System.out.println("Is before tomorrow? " + isBefore); String formattedDate = now.format("YYYY/MM/dd"); System.out.println("Formatted date: " + formattedDate); Moment parsedDate = Moment.parse("2022-01-01", "YYYY-MM-dd"); System.out.println("Parsed date: " + parsedDate.format("YYYY-MM-dd")); } }


上一篇:
下一篇:
切换中文