{"id":20929668,"url":"https://github.com/swiftech/swifttime","last_synced_at":"2025-06-30T10:06:23.003Z","repository":{"id":57723459,"uuid":"121397834","full_name":"swiftech/swifttime","owner":"swiftech","description":"SwiftTime is a very light weight extension of Java GregorianCalendar class.","archived":false,"fork":false,"pushed_at":"2020-10-13T06:52:47.000Z","size":29,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T18:47:29.226Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swiftech.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T15:16:12.000Z","updated_at":"2019-07-20T18:22:25.000Z","dependencies_parsed_at":"2022-08-28T15:00:23.183Z","dependency_job_id":null,"html_url":"https://github.com/swiftech/swifttime","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftech%2Fswifttime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftech%2Fswifttime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftech%2Fswifttime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftech%2Fswifttime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiftech","download_url":"https://codeload.github.com/swiftech/swifttime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243324267,"owners_count":20273099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T21:22:41.963Z","updated_at":"2025-03-13T01:42:31.941Z","avatar_url":"https://github.com/swiftech.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SwiftTime \n\nSwiftTime is a very light weight extension of Java GregorianCalendar class. \nProvides more common operation for you to easily manipulating time without any other dependencies.\n\n\n## Features\n* Easily increase or decrease any field of time.\n* Truncate time at any field of time.\n* Get interval at any filed of time.\n* First or last day of current month or week.\n* Month starts with 1 not 0 by GregorianCalendar default.\n\n\n## Tutorial\n\n#### Construct\nYou can construct a new Time simply by:\n```java\n// t is just current time whose value is the same to System.currentTimeMillis().\nTime t = new Time();\n```\n\nor from other time types:\n```java\njava.util.Date date = new java.util.Date();\n...\nTime t = new Time(date);\n```\n\nof course by fields of time:\n```java\nTime t = new Time(2018, 02, 13, 22, 06, 30);\n```\n\u003e if the hour, minute, second fields is not given, their default value will be 0.\n\u003e if the dayOfMonth is not given, the default value is 1\n\u003e if the month is not given, the default value is 1, which means January.\n\n#### Increase or decrease single field of time\nIncrease or decrease time become more simple and straightforward:\n```java\n// Increase 3 years\nt.increaseYears(3);\n\n// Decrease 8 hours\nt.increaseHours(-8);\n```\n\n\n#### Truncate time\nUsually you need to get the precise second of a imprecise time, for example:\nGet the first day of this month but hour, minute and second be truncated to 00:00:00 .\nIt is easy to do so now:\n```java\nTime t = new Time(); //current time is 2018-02-13 22:06:30 for example\nt.truncateAtMonth();\nSystem.out.println(t);\n\u003e Thu Feb 01 00:00:00 CST 2018\n\n```\n\n#### Interval for fields\nCalculate time interval at single time field is tedious because you have to consider the carry of time field.\nNow you can easily get interval at any field from one Time to another. eg:\n```java\nTime t1 = new Time(2018);\nTime t2 = new Time(2000);\nt1.getYearIntervalFrom(t2);\nSystem.out.println(t);\n\u003e 18\n```\n\u003e of course other fields of time can be done as well.\n\n\n#### Set time\n* Set time to the first day of this week\n```java\nt.setToFirstDayOfCurrentWeek();\n```\n\n* Set time to the last day of this week\n```java\nt.setToLastDayOfCurrentWeek();\n```\n\n\n#### Combination\nYou can use methods of Time combined to get useful effect, eg:\n\n```java\n\n// get the first second of specified day of month\nt.setDate(3).truncateAtHour();\n\n// get the first second of the first day of this week\nt.setToFirstDayOfCurrentWeek().truncateAtHour();\n```\n\n\n#### Misc\n```java\n// get days of month\nTime.getDaysOfCurrentMonth(t);\n\n\n```\n\n\n#### Maven\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.github.swiftech\u003c/groupId\u003e\n\t\u003cartifactId\u003eswifttime\u003c/artifactId\u003e\n\t\u003cversion\u003e0.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftech%2Fswifttime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftech%2Fswifttime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftech%2Fswifttime/lists"}