• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • now ( 'long' | DATEFORMAT )

    Prev Next
    Macro
    Get current date and time in various formats

    Summary

    The now macro returns the current date and time. It can return the raw Date object, milliseconds since epoch, or a formatted date string.

    Syntax

    ${now[;<format>]}
    

    Parameters

    • format (optional) - Either “long” for milliseconds, a date format pattern, or omit for default Date format

    Behavior

    • No argument: Returns default Date string representation
    • “long”: Returns milliseconds since Unix epoch
    • Format pattern: Returns formatted date string using SimpleDateFormat

    Examples

    Get current time in millis:

    ${now;long}
    # Returns: 1700000000000 (example)
    

    Custom format:

    ${now;yyyy-MM-dd HH:mm:ss}
    # Returns: "2024-11-20 10:30:45"
    

    ISO format:

    ${now;yyyy-MM-dd'T'HH:mm:ss'Z'}
    # Returns: "2024-11-20T10:30:45Z"
    

    Default format:

    ${now}
    # Returns: "Wed Nov 20 10:30:45 UTC 2024"
    

    Build timestamp:

    Build-Time: ${now;yyyy-MM-dd HH:mm z}
    

    Use Cases

    • Build timestamps
    • Current time logging
    • Time-based conditionals
    • Unique identifiers with timestamps
    • Build metadata

    Notes

    • Uses system time zone unless specified in format
    • Format uses SimpleDateFormat patterns
    • “long” returns milliseconds as number
    • Default returns Java Date.toString() format
    • See also: ${tstamp} for more control
    • See also: ${currenttime} for millis only

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home