Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bardiademon/time
Time
https://github.com/bardiademon/time
bardiademon dev java javase time time-management
Last synced: about 1 month ago
JSON representation
Time
- Host: GitHub
- URL: https://github.com/bardiademon/time
- Owner: bardiademon
- Created: 2023-12-24T08:19:35.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2023-12-24T08:20:15.000Z (11 months ago)
- Last Synced: 2024-09-30T13:23:37.522Z (about 2 months ago)
- Topics: bardiademon, dev, java, javase, time, time-management
- Language: Java
- Homepage: https://bardiademon.com
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BTime - Flexible Time Management Class
`BTime` is a Java class designed to facilitate flexible time management, allowing you to manipulate time by adding days,
hours, minutes, and seconds with customizable formatting. Whether you need to calculate elapsed time, set specific
durations, or display time in a particular format, `BTime` has you covered.This code is built for Java 8, the latest LTS.
[Click to download](https://dev.java)## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Creating an Instance](#creating-an-instance)
- [Manipulating Time](#manipulating-time)
- [Formatting](#formatting)
- [Examples](#examples)
- [Contributing](#contributing)## Installation
To use the `BTime` class in your Java project, you can simply copy the provided `BTime.java` file into your source code
directory.## Usage
### Creating an Instance
You can create a `BTime` instance in multiple ways:
- Creating an instance initialized to zero:
```java
public class Main {
public static void main(String[] args) {
BTime myTime = BTime.ofZero();
}
}
```- Creating an instance with a specific duration in seconds, minutes, hours, or days:
```java
public class Main {
public static void main(String[] args) {
BTime myTime = BTime.ofSeconds(120);
}
}
```### Manipulating Time
BTime provides methods for adding and subtracting time in various units:
Adding and subtracting seconds, minutes, hours, and days:
```java
public class Main {
public static void main(String[] args) {
myTime.plusSeconds(30);
myTime.minusMinutes(15);
}
}
```### Formatting
You can format the BTime instance as a string using a customizable pattern. Supported patterns include:
d: Days
h: Hours
m: Minutes
s: Seconds
Patterns with two characters (e.g., dd, hh) will add leading zeros for values below 10.### Examples:
```java
public class Main {
public static void main(String[] args) {
String formattedTime = myTime.format("hh:mm:ss");
System.out.println(formattedTime); // Output: 00:02:05
}
}
```Here's an additional example where 8 days are added to a BTime instance, and the time is formatted as "hh:mm:ss":
```java
public class Main {
public static void main(String[] args) {
// Creating an instance
BTime myTime = BTime.ofZero();// Adding 8 days
myTime.plusDay(8);// Formatting as a string
String formattedTime = myTime.format("hh:mm:ss");
System.out.println(formattedTime); // Output: 192:00:00
}
}
```Here are a few examples to illustrate the capabilities of the BTime class:
```java
public class Main {
public static void main(String[] args) {
// Creating an instance
BTime myTime = BTime.ofMinutes(125);// Manipulating time
myTime.plusSeconds(30);
myTime.minusHours(1);// Formatting as a string
String formattedTime = myTime.format("hh:mm:ss");
System.out.println(formattedTime); // Output: 01:05:30}
}
```### Contributing
If you have suggestions, improvements, or find any issues, feel free to open an issue or submit a pull request. Your
contributions are highly appreciated!
💻 Technologies
🌟 Spread the word!If you want to say thank you:
- Add a GitHub Star to the project!
- Follow my GitHub [bardiademon](https://github.com/bardiademon)
⚠️ License & 📝 Creditsby bardiademon [https://bardiademon.com](https://www.bardiademon.com)