from typing import Optional
from datetime import datetime


def get_timestamp(tstamp: Optional[datetime] = None) -> object:
    """Get a string representing the a time stamp.

    Args:
        tstamp: datetime.datetime object representing date and time. If set to None,
            the current time is taken.

    Returns:
        str: String representation of the time stamp.
    """
    tstamp = tstamp or datetime.now()
    return (
        f"{str(tstamp.year).zfill(4)}_{str(tstamp.month).zfill(2)}_"
        f"{str(tstamp.day).zfill(2)}_"
        f"{str(tstamp.hour).zfill(2)}_{str(tstamp.minute).zfill(2)}_"
        f"{str(tstamp.second).zfill(2)}_{str(tstamp.microsecond).zfill(6)}"
    )