Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Time formatting snippets
- ### Java
- ```java
- import java.util.Date;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- private String getTime() {
- DateFormat dateFormat = new SimpleDateFormat("[dd.MM.yyyy - HH:mm:ss]");
- return dateFormat.format(new Date());
- }
- ```
- ### Python
- ```python
- from time import gmtime, strftime
- def get_time():
- return strftime("[%d.%m.%Y - %H:%M:%S]", gmtime())
- ```
- ### JavaScript
- ```javascript
- // That method is verry rough. Is there a better way?
- function getTime() {
- function btf(inp) {
- if (inp < 10)
- return "0" + inp;
- return inp;
- }
- var date = new Date(),
- y = date.getFullYear(),
- m = btf(date.getMonth()),
- d = btf(date.getDate()),
- h = btf(date.getHours()),
- min = btf(date.getMinutes()),
- s = btf(date.getSeconds());
- return "[" + d + "." + m + "." + y + " - " + h + ":" + m + ":" + s + "]" ;
- }
- ```
- ### C#
- ```c#
- private string GetTime() {
- return DateTime.Now.ToString("[dd.MM.yyyy - HH:mm:ss]");
- }
- ```
- *Write some other time formating functions for other languages in the comments below and I will add them to the snippet ;)*
Add Comment
Please, Sign In to add comment